mirror of
https://github.com/vlang/v.git
synced 2025-09-16 16:02:29 +03:00
math.big: make is_power_of_2() be false for negatives (it now matches Julia's ispow2/1) (#24619)
This commit is contained in:
parent
a1c5f41c6b
commit
b19fa76c6e
2 changed files with 2 additions and 1 deletions
|
@ -110,6 +110,7 @@ struct IsXTest {
|
||||||
|
|
||||||
// vfmt off
|
// vfmt off
|
||||||
const is_power_of_2_test_data = [
|
const is_power_of_2_test_data = [
|
||||||
|
IsXTest{ "-4", false },
|
||||||
IsXTest{ u32(0b110000000000), false },
|
IsXTest{ u32(0b110000000000), false },
|
||||||
IsXTest{ "537502395172353242345", false },
|
IsXTest{ "537502395172353242345", false },
|
||||||
IsXTest{ "590295810358705700000", false },
|
IsXTest{ "590295810358705700000", false },
|
||||||
|
|
|
@ -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`
|
// is_power_of_2 returns true when the integer `x` satisfies `2^n`, where `n >= 0`
|
||||||
@[direct_array_access; inline]
|
@[direct_array_access; inline]
|
||||||
pub fn (x Integer) is_power_of_2() bool {
|
pub fn (x Integer) is_power_of_2() bool {
|
||||||
if x.signum == 0 {
|
if x.signum <= 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue