-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.go
88 lines (81 loc) · 1.39 KB
/
Utils.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
81
82
83
84
85
86
87
88
// Utils
package BigInteger
const HEX = 10000 //Hexadecimal 进制
func min(a, b int32) int32 {
if a > b {
return b
}
return a
}
func max(a, b int32) int32 {
if a > b {
return a
}
return b
}
func MaxBigIntAbs(a, b *BigInteger) *BigInteger {
aLen := len(a.Value)
bLen := len(b.Value)
if aLen > bLen {
return a
} else if aLen < bLen {
return b
} else {
for i := aLen - 1; i >= 0; i-- {
if a.Value[i] > b.Value[i] {
return a
} else if a.Value[i] < b.Value[i] {
return b
}
}
}
return a
}
func MinBigIntAbs(a, b *BigInteger) *BigInteger {
aLen := len(a.Value)
bLen := len(b.Value)
if aLen > bLen {
return b
} else if aLen < bLen {
return a
} else {
for i := aLen - 1; i >= 0; i-- {
if a.Value[i] > b.Value[i] {
return b
} else if a.Value[i] < b.Value[i] {
return a
}
}
}
return a
}
func MaxBigInt(a, b *BigInteger) *BigInteger {
if a.Positive != b.Positive {
if a.Positive {
return a
} else {
return b
}
} else {
if a.Positive {
return MaxBigIntAbs(a, b)
} else {
return MinBigIntAbs(a, b)
}
}
}
func MinBigInt(a, b *BigInteger) *BigInteger {
if a.Positive != b.Positive {
if a.Positive {
return b
} else {
return a
}
} else {
if a.Positive {
return MinBigIntAbs(a, b)
} else {
return MaxBigIntAbs(a, b)
}
}
}