Source file
test/codegen/generics.go
1
2
3
4
5
6
7 package codegen
8
9 import "cmp"
10
11 func isNaN[T cmp.Ordered](x T) bool {
12 return x != x
13 }
14
15 func compare[T cmp.Ordered](x, y T) int {
16
17
18 xNaN := isNaN(x)
19 yNaN := isNaN(y)
20 if xNaN {
21 if yNaN {
22 return 0
23 }
24 return -1
25 }
26 if yNaN {
27 return +1
28 }
29 if x < y {
30 return -1
31 }
32 if x > y {
33 return +1
34 }
35 return 0
36 }
37
38 func usesCompare(a, b int) int {
39 return compare(a, b)
40 }
41
View as plain text