Skip to content

Commit b19fa76

Browse files
authored
math.big: make is_power_of_2() be false for negatives (it now matches Julia's ispow2/1) (#24619)
1 parent a1c5f41 commit b19fa76

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

vlib/math/big/big_test.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct IsXTest {
110110

111111
// vfmt off
112112
const is_power_of_2_test_data = [
113+
IsXTest{ "-4", false },
113114
IsXTest{ u32(0b110000000000), false },
114115
IsXTest{ "537502395172353242345", false },
115116
IsXTest{ "590295810358705700000", false },

vlib/math/big/integer.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ pub fn (x Integer) is_odd() bool {
12141214
// is_power_of_2 returns true when the integer `x` satisfies `2^n`, where `n >= 0`
12151215
@[direct_array_access; inline]
12161216
pub fn (x Integer) is_power_of_2() bool {
1217-
if x.signum == 0 {
1217+
if x.signum <= 0 {
12181218
return false
12191219
}
12201220

0 commit comments

Comments
 (0)