-
Notifications
You must be signed in to change notification settings - Fork 0
/
constraint.go
80 lines (66 loc) · 1.84 KB
/
constraint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package constraint
// SPDX-License-Identifier: Apache-2.0
import (
"math/big"
)
// SPDX-License-Identifier: Apache-2.0
// SignedInteger is copied from golang.org/x/exp/constraints#Signed
type SignedInteger interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}
// UnsignedInteger is like golang.org/x/exp/constraints#Unsigned, except no uintptr
type UnsignedInteger interface {
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}
// Integer is equivalent to golang.org/x/exp/constraints#Integer
type Integer interface {
SignedInteger | UnsignedInteger
}
// Float is copied from golang.org/x/exp/constraints#Float
type Float interface {
~float32 | ~float64
}
// Signed differs from golang.org/x/exp/constraints#Signed - it includes Float
type Signed interface {
SignedInteger | Float
}
// IntegerAndFloat describes any signed or unsigned integer type and any float type
type IntegerAndFloat interface {
Integer | Float
}
// Numeric describes any numeric type except complex
type Numeric interface {
IntegerAndFloat | *big.Int | *big.Float | *big.Rat
}
// Ordered is equivalent to golang.org/x/exp/constraints#Ordered
type Ordered interface {
Signed | UnsignedInteger | ~string
}
// Complex is copied from golang.org/x/exp/constraints#Complex
type Complex interface {
~complex64 | ~complex128
}
// Cmp is a companion interface for Ordered
// Embeds comparable so that the Cmp interface can be a map key
type Cmp[T any] interface {
comparable
// Returns <0 if this value < argument
// 0 if this value = argument
// >0 if this value > argument
Cmp(T) int
}
// BigOps is an interface that describes all the common methods of the provided go big types
type BigOps[T any] interface {
Abs(T) T
Add(T, T) T
Cmp(T) int
Mul(T, T) T
Neg(T) T
Quo(T, T) T
Set(T) T
SetInt64(int64) T
SetUint64(uint64) T
Sign() int
String() string
Sub(T, T) T
}