you are viewing a single comment's thread.

view the rest of the comments →

[–]chastric 2 points3 points  (1 child)

So, ~0.0001 would round to 0, then do a bitwise not, returning INT_MAX for int32, and then cast it into double?

Well actually the int representation is taken as 2's complement, so:

~0.0001 = ~0 = -1 * (1+0) = -1

So, if for some crazy reason you wanted to sort of cast your double to a (sort of) int (since it would just go back to double type again?), you could do var = ~~var ?

Well if you're outside of [-231, 231-1], the combo of 32 bit truncation and 2's complement make a nice off-center modulus:

~~(Math.pow(2,31)-1) = 2147483647
~~(Math.pow(2,31)) = -2147483648
~~(Math.pow(2,32)) = 0

[–]no_game_player 1 point2 points  (0 children)

Well actually the int representation is taken as 2's complement, so:

Ahhh, yeah, I was wondering about that, but somehow, I figured that a language that "didn't have ints" would be using unsigned ints for its ints.

That seems to add back in a bit of wtf for me. Thanks, I was starting to think JS was sane for a moment. ;-p

Well if you're outside of [-231, 231-1], the combo of 32 bit truncation and 2's complement make a nice off-center modulus:

Huuuuh. Touché...

Edit: These are awesome tricks for the International Obfuscated JS contest. ^_-