@@ -34,13 +34,12 @@ func limitUnsigned256(x *Number) *Number {
34
34
func limitSigned256 (x * Number ) * Number {
35
35
if x .num .Cmp (tt255 ) < 0 {
36
36
return x
37
- } else {
38
- x .num .Sub (x .num , tt256 )
39
- return x
40
37
}
38
+ x .num .Sub (x .num , tt256 )
39
+ return x
41
40
}
42
41
43
- // Number function
42
+ // Initialiser is a Number function
44
43
type Initialiser func (n int64 ) * Number
45
44
46
45
// A Number represents a generic integer with a bounding function limiter. Limit is called after each operations
@@ -51,79 +50,79 @@ type Number struct {
51
50
limit func (n * Number ) * Number
52
51
}
53
52
54
- // Returns a new initialiser for a new *Number without having to expose certain fields
53
+ // NewInitialiser returns a new initialiser for a new *Number without having to expose certain fields
55
54
func NewInitialiser (limiter func (* Number ) * Number ) Initialiser {
56
55
return func (n int64 ) * Number {
57
56
return & Number {big .NewInt (n ), limiter }
58
57
}
59
58
}
60
59
61
- // Return a Number with a UNSIGNED limiter up to 256 bits
60
+ // Uint256 returns a Number with a UNSIGNED limiter up to 256 bits
62
61
func Uint256 (n int64 ) * Number {
63
62
return & Number {big .NewInt (n ), limitUnsigned256 }
64
63
}
65
64
66
- // Return a Number with a SIGNED limiter up to 256 bits
65
+ // Int256 returns Number with a SIGNED limiter up to 256 bits
67
66
func Int256 (n int64 ) * Number {
68
67
return & Number {big .NewInt (n ), limitSigned256 }
69
68
}
70
69
71
- // Returns a Number with a SIGNED unlimited size
70
+ // Big returns a Number with a SIGNED unlimited size
72
71
func Big (n int64 ) * Number {
73
72
return & Number {big .NewInt (n ), func (x * Number ) * Number { return x }}
74
73
}
75
74
76
- // Sets i to sum of x+y
75
+ // Add sets i to sum of x+y
77
76
func (i * Number ) Add (x , y * Number ) * Number {
78
77
i .num .Add (x .num , y .num )
79
78
return i .limit (i )
80
79
}
81
80
82
- // Sets i to difference of x-y
81
+ // Sub sets i to difference of x-y
83
82
func (i * Number ) Sub (x , y * Number ) * Number {
84
83
i .num .Sub (x .num , y .num )
85
84
return i .limit (i )
86
85
}
87
86
88
- // Sets i to product of x*y
87
+ // Mul sets i to product of x*y
89
88
func (i * Number ) Mul (x , y * Number ) * Number {
90
89
i .num .Mul (x .num , y .num )
91
90
return i .limit (i )
92
91
}
93
92
94
- // Sets i to the quotient prodject of x/y
93
+ // Div sets i to the quotient prodject of x/y
95
94
func (i * Number ) Div (x , y * Number ) * Number {
96
95
i .num .Div (x .num , y .num )
97
96
return i .limit (i )
98
97
}
99
98
100
- // Sets i to x % y
99
+ // Mod sets i to x % y
101
100
func (i * Number ) Mod (x , y * Number ) * Number {
102
101
i .num .Mod (x .num , y .num )
103
102
return i .limit (i )
104
103
}
105
104
106
- // Sets i to x << s
105
+ // Lsh sets i to x << s
107
106
func (i * Number ) Lsh (x * Number , s uint ) * Number {
108
107
i .num .Lsh (x .num , s )
109
108
return i .limit (i )
110
109
}
111
110
112
- // Sets i to x^y
111
+ // Pow sets i to x^y
113
112
func (i * Number ) Pow (x , y * Number ) * Number {
114
113
i .num .Exp (x .num , y .num , big .NewInt (0 ))
115
114
return i .limit (i )
116
115
}
117
116
118
117
// Setters
119
118
120
- // Set x to i
119
+ // Set sets x to i
121
120
func (i * Number ) Set (x * Number ) * Number {
122
121
i .num .Set (x .num )
123
122
return i .limit (i )
124
123
}
125
124
126
- // Set x bytes to i
125
+ // SetBytes sets x bytes to i
127
126
func (i * Number ) SetBytes (x []byte ) * Number {
128
127
i .num .SetBytes (x )
129
128
return i .limit (i )
@@ -140,12 +139,12 @@ func (i *Number) Cmp(x *Number) int {
140
139
141
140
// Getters
142
141
143
- // Returns the string representation of i
142
+ // String returns the string representation of i
144
143
func (i * Number ) String () string {
145
144
return i .num .String ()
146
145
}
147
146
148
- // Returns the byte representation of i
147
+ // Bytes returns the byte representation of i
149
148
func (i * Number ) Bytes () []byte {
150
149
return i .num .Bytes ()
151
150
}
@@ -160,17 +159,17 @@ func (i *Number) Int64() int64 {
160
159
return i .num .Int64 ()
161
160
}
162
161
163
- // Returns the signed version of i
162
+ // Int256 returns the signed version of i
164
163
func (i * Number ) Int256 () * Number {
165
164
return Int (0 ).Set (i )
166
165
}
167
166
168
- // Returns the unsigned version of i
167
+ // Uint256 returns the unsigned version of i
169
168
func (i * Number ) Uint256 () * Number {
170
169
return Uint (0 ).Set (i )
171
170
}
172
171
173
- // Returns the index of the first bit that's set to 1
172
+ // FirstBitSet returns the index of the first bit that's set to 1
174
173
func (i * Number ) FirstBitSet () int {
175
174
for j := 0 ; j < i .num .BitLen (); j ++ {
176
175
if i .num .Bit (j ) > 0 {
0 commit comments