Skip to content

Commit f0c3374

Browse files
committed
Check special case in BigInt::bit
1 parent f7199bd commit f0c3374

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/bigint.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,11 +3263,12 @@ impl BigInt {
32633263
// Then the two's complement is
32643264
// ... 1 !x 1 0 ... 0
32653265
// where !x is obtained from x by flipping each bit
3266-
let b = self.data.bit(bit);
3267-
if self.is_negative() && bit > self.data.trailing_zeros().unwrap() {
3268-
!b
3266+
if bit >= u64::from(big_digit::BITS) * self.len() as u64 {
3267+
self.is_negative()
3268+
} else if self.is_negative() && bit > self.data.trailing_zeros().unwrap() {
3269+
!self.data.bit(bit)
32693270
} else {
3270-
b
3271+
self.data.bit(bit)
32713272
}
32723273
}
32733274

0 commit comments

Comments
 (0)