You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Saw this repo b/c it was in js weekly newsletter. B/c of the way bitwise AND work on numbers in JS (casting down to 32-bit signed integers), the isPowerOfTwo function will return a lot of false positives:
// Any non-integer `< 2 ** 32` will be floored.// Below, the bitwise operation turns 1.5 into 1.isPowerOfTwo(1.5);// true// Only the least-significant 32 bits are saved in bitwise ops.// Below, the bitwise operation turns number into 1.isPowerOfTwo(2**40+1);// true
though afaik it should work with it's BigInt variant:
Saw this repo b/c it was in js weekly newsletter. B/c of the way bitwise AND work on
number
s in JS (casting down to 32-bit signed integers), theisPowerOfTwo
function will return a lot of false positives:though afaik it should work with it's BigInt variant:
Maybe add a disclaimer to the function specifying that it only works on positive integers <= 2 ** 32?
The text was updated successfully, but these errors were encountered: