~~ Two tildes
Suddenly I met such a JS-code: I
immediately remembered that ~ is a bit complement, it seemed that it was written simply.
However, bit operations are applicable only to integers, so there is still an implicit type conversion. The shortest way to write
But do not fall for a short cool record: it
var a = ~~b;
immediately remembered that ~ is a bit complement, it seemed that it was written simply.
var a = b;
However, bit operations are applicable only to integers, so there is still an implicit type conversion. The shortest way to write
var a = Math.floor(b);
? But do not fall for a short cool record: it
Math.floor()
works twice as fast (checked in FF3.6). ~~$x
for rounding it works in Pearl, and as much in time as it does int($x)
. I wonder what in other languages? Will it work in Python, too? Upd: did not work.