...
1
2
3
4
5
6
7
8
9 package p
10
11 type F {
12 float64
13 }
14
15 func _[T F | int](x T) {
16 _ = x == 0
17 }
18
19
20
21 type FloatType {
22 float32 | float64
23 }
24
25 type IntegerType interface {
26 int8 | int16 | int32 | int64 | int |
27 uint8 | uint16 | uint32 | uint64 | uint
28 }
29
30 type ComplexType interface {
31 complex64 | complex128
32 }
33
34 type Number interface {
35 FloatType | IntegerType | ComplexType
36 }
37
38 func GetDefaultNumber[T Number](value, defaultValue T) T {
39 if value == 0 {
40 return defaultValue
41 }
42 return value
43 }
44
View as plain text