@@ -94,7 +94,7 @@ pub fn (u Uint256) xor_128(v Uint128) Uint256 {
94
94
return Uint256 {u.lo.xor (v), u.hi}
95
95
}
96
96
97
- // add_256 - untested
97
+ // add_256 return u + v and the carry
98
98
pub fn add_256 (x Uint256 , y Uint256 , carry u64 ) (Uint256 , u64 ) {
99
99
mut sum := Uint256 {}
100
100
mut carry_out := u64 (0 )
@@ -103,7 +103,7 @@ pub fn add_256(x Uint256, y Uint256, carry u64) (Uint256, u64) {
103
103
return sum, carry_out
104
104
}
105
105
106
- // sub_256 - untested
106
+ // sub_256 returns u - v and the borrow
107
107
pub fn sub_256 (x Uint256 , y Uint256 , borrow u64 ) (Uint256 , u64 ) {
108
108
mut diff := Uint256 {}
109
109
mut borrow_out := u64 (0 )
@@ -112,7 +112,7 @@ pub fn sub_256(x Uint256, y Uint256, borrow u64) (Uint256, u64) {
112
112
return diff, borrow_out
113
113
}
114
114
115
- // mul_256 - untested
115
+ // mul_256 returns u x v
116
116
pub fn mul_256 (x Uint256 , y Uint256 ) (Uint256 , Uint256 ) {
117
117
mut hi := Uint256 {}
118
118
mut lo := Uint256 {}
@@ -140,7 +140,7 @@ pub fn (u Uint256) add(v Uint256) Uint256 {
140
140
return sum
141
141
}
142
142
143
- // overflowing_add - untested
143
+ // overflowing_add returns u + v even if result size > 256
144
144
pub fn (u Uint256) overflowing_add (v Uint256 ) (Uint256 , u64 ) {
145
145
sum , overflow := add_256 (u, v, 0 )
146
146
return sum, overflow
@@ -178,7 +178,7 @@ pub fn (u Uint256) mul_128(v Uint128) Uint256 {
178
178
return Uint256 {lo, hi.add (u.hi.mul (v))}
179
179
}
180
180
181
- // quo_rem - untested
181
+ // quo_rem returns q = u/v and r = u%v
182
182
pub fn (u Uint256) quo_rem (v Uint256 ) (Uint256 , Uint256 ) {
183
183
if v.hi.is_zero () && v.lo.hi == 0 {
184
184
q , r := u.quo_rem_64 (v.lo.lo)
@@ -206,7 +206,7 @@ pub fn (u Uint256) quo_rem(v Uint256) (Uint256, Uint256) {
206
206
return q, r
207
207
}
208
208
209
- // quo_rem_128 - untested
209
+ // quo_rem_128 returns q = u/v and r = u%v
210
210
pub fn (u Uint256) quo_rem_128 (v Uint128 ) (Uint256 , Uint128 ) {
211
211
if u.hi.cmp (v) < 0 {
212
212
lo , r := div_128 (u.hi, u.lo, v)
@@ -218,7 +218,7 @@ pub fn (u Uint256) quo_rem_128(v Uint128) (Uint256, Uint128) {
218
218
return Uint256 {lo, hi}, r2
219
219
}
220
220
221
- // quo_rem_64 - untested
221
+ // quo_rem_64 returns q = u/v and r = u%v
222
222
pub fn (u Uint256) quo_rem_64 (v u64 ) (Uint256 , u64 ) {
223
223
mut q := Uint256 {}
224
224
mut r := u64 (0 )
@@ -287,37 +287,37 @@ pub fn (u Uint256) lsh(n u32) Uint256 {
287
287
return s
288
288
}
289
289
290
- // div - untested
290
+ // div returns u / v
291
291
pub fn (u Uint256) div (v Uint256 ) Uint256 {
292
292
q , _ := u.quo_rem (v)
293
293
return q
294
294
}
295
295
296
- // div_128 - untested
296
+ // div_128 returns u / v
297
297
pub fn (u Uint256) div_128 (v Uint128 ) Uint256 {
298
298
q , _ := u.quo_rem_128 (v)
299
299
return q
300
300
}
301
301
302
- // div_64 - untested
302
+ // div_64 returns u / v
303
303
pub fn (u Uint256) div_64 (v u64 ) Uint256 {
304
304
q , _ := u.quo_rem_64 (v)
305
305
return q
306
306
}
307
307
308
- // mod - untested
308
+ // mod returns r = u % v
309
309
pub fn (u Uint256) mod (v Uint256 ) Uint256 {
310
310
_ , r := u.quo_rem (v)
311
311
return r
312
312
}
313
313
314
- // mod_128 - untested
314
+ // mod_128 returns r = u % v
315
315
pub fn (u Uint256) mod_128 (v Uint128 ) Uint128 {
316
316
_ , r := u.quo_rem_128 (v)
317
317
return r
318
318
}
319
319
320
- // mod_64 - untested
320
+ // mod_64 returns r = u % v
321
321
pub fn (u Uint256) mod_64 (v u64 ) u64 {
322
322
_ , r := u.quo_rem_64 (v)
323
323
return r
0 commit comments