Skip to content

Commit 0246ef1

Browse files
committed
BigInt prototype: Fix Bit.leadingZero/trailingZero
1 parent 826f8da commit 0246ef1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/Prototypes/BigInt.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ struct Bit : FixedWidthInteger, UnsignedInteger {
12481248
}
12491249

12501250
var trailingZeroBitCount: Int {
1251-
return value.trailingZeroBitCount
1251+
return Int(~value & 1)
12521252
}
12531253

12541254
static var max: Bit {
@@ -1268,7 +1268,7 @@ struct Bit : FixedWidthInteger, UnsignedInteger {
12681268
}
12691269

12701270
var leadingZeroBitCount: Int {
1271-
return value.nonzeroBitCount - 7
1271+
return Int(~value & 1)
12721272
}
12731273

12741274
var bigEndian: Bit {
@@ -1489,6 +1489,15 @@ BitTests.test("Basics") {
14891489

14901490
expectEqual(x, x + y)
14911491
expectGT(x, x &+ x)
1492+
1493+
expectEqual(1, x.nonzeroBitCount)
1494+
expectEqual(0, y.nonzeroBitCount)
1495+
1496+
expectEqual(0, x.leadingZeroBitCount)
1497+
expectEqual(1, y.leadingZeroBitCount)
1498+
1499+
expectEqual(0, x.trailingZeroBitCount)
1500+
expectEqual(1, y.trailingZeroBitCount)
14921501
}
14931502

14941503
var BigIntTests = TestSuite("BigInt")

0 commit comments

Comments
 (0)