-
Notifications
You must be signed in to change notification settings - Fork 7
/
rawmath.go
35 lines (28 loc) · 891 Bytes
/
rawmath.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
package Numbers
import "math/big"
// Divide divides the a by b
func (a *RawAmount) Divide(b *RawAmount) *RawAmount {
return &RawAmount{new(big.Int).Div(a.bigint, b.bigint)}
}
// Multiply multiplies the a by b
func (a *RawAmount) Multiply(b *RawAmount) *RawAmount {
return &RawAmount{new(big.Int).Mul(a.bigint, b.bigint)}
}
// Subtract subtracts the a by b
func (a *RawAmount) Subtract(b *RawAmount) *RawAmount {
return &RawAmount{new(big.Int).Sub(a.bigint, b.bigint)}
}
// Add adds the a by b
func (a *RawAmount) Add(b *RawAmount) *RawAmount {
return &RawAmount{new(big.Int).Add(a.bigint, b.bigint)}
}
// Compare compares a with b, return
// -1 if a < b
// 0 if a == b
// +1 if a > b
func (a *RawAmount) Compare(b *RawAmount) int {
return a.bigint.Cmp(b.bigint)
}
func (a *RawAmount) IsValid() bool {
return a.bigint.Cmp(INT128_LIMIT) < 0 || a.bigint.Cmp(INT128_LIMIT) > 0
}