Bitwise operators don't work on big integer arithmetic

untitled script pic - 2026-08-08T234109.687
Always returns -1, but I would expect it to wrap around

It’s a limitation not a bug :slight_smile:

The bit operators are just for numbers represented by 32 bits (using 2’s complement)

The bitwise operators are in JS. Blame it on the JS bitwise operators. The developers took the easy way out with that instead of implementing it in Snap! :)

Its not a case of “easy way out” :slight_smile:

If you choose to uses a 2s complement system - you have to predecide on the number of bits to use.

That’s not the problem –
I would expect it to overflow into negative number for n > 2147483647, but it instead gets coerced into JS Infinity

ackshyually, you do not!!

converted directly into javascript, using BigInts:

~((2n*(10n**308n))*3n)

returns:

-600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n

because it is perfectly possible to have bitwise operations on arbitrary-precision integers

2’s complement works perfectly fine with infinite bits, you just say that negative numbers have "1"s infinitely to the left, and positive numbers have an infinite sea of "0"s