math.big: make is_power_of_2() be false for negatives (it now matches Julia's ispow2/1) (#24619)

This commit is contained in:
Mike 2025-05-31 08:11:16 +03:00 committed by GitHub
parent a1c5f41c6b
commit b19fa76c6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -110,6 +110,7 @@ struct IsXTest {
// vfmt off
const is_power_of_2_test_data = [
IsXTest{ "-4", false },
IsXTest{ u32(0b110000000000), false },
IsXTest{ "537502395172353242345", false },
IsXTest{ "590295810358705700000", false },

View File

@ -1214,7 +1214,7 @@ pub fn (x Integer) is_odd() bool {
// is_power_of_2 returns true when the integer `x` satisfies `2^n`, where `n >= 0`
@[direct_array_access; inline]
pub fn (x Integer) is_power_of_2() bool {
if x.signum == 0 {
if x.signum <= 0 {
return false
}