File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -448,6 +448,12 @@ func (x *Int) BitLen() int {
448
448
return x .abs .bitLen ()
449
449
}
450
450
451
+ // TrailingZeroBits returns the number of consecutive least significant zero
452
+ // bits of |x|.
453
+ func (x * Int ) TrailingZeroBits () uint {
454
+ return x .abs .trailingZeroBits ()
455
+ }
456
+
451
457
// Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z.
452
458
// If m == nil or m == 0, z = x**y unless y <= 0 then z = 1.
453
459
//
Original file line number Diff line number Diff line change @@ -1335,6 +1335,31 @@ func TestBitSet(t *testing.T) {
1335
1335
}
1336
1336
}
1337
1337
1338
+ var tzbTests = []struct {
1339
+ in string
1340
+ out uint
1341
+ }{
1342
+ {"0" , 0 },
1343
+ {"1" , 0 },
1344
+ {"-1" , 0 },
1345
+ {"4" , 2 },
1346
+ {"-8" , 3 },
1347
+ {"0x4000000000000000000" , 74 },
1348
+ {"-0x8000000000000000000" , 75 },
1349
+ }
1350
+
1351
+ func TestTrailingZeroBits (t * testing.T ) {
1352
+ for i , test := range tzbTests {
1353
+ in , _ := new (Int ).SetString (test .in , 0 )
1354
+ want := test .out
1355
+ got := in .TrailingZeroBits ()
1356
+
1357
+ if got != want {
1358
+ t .Errorf ("#%d: got %v want %v" , i , got , want )
1359
+ }
1360
+ }
1361
+ }
1362
+
1338
1363
func BenchmarkBitset (b * testing.B ) {
1339
1364
z := new (Int )
1340
1365
z .SetBit (z , 512 , 1 )
You can’t perform that action at this time.
0 commit comments