📜 ⬆️ ⬇️

~~ Two tildes

Suddenly I met this JS code:
var a = ~~b;
Immediately I remembered that ~ is a bit addition, it seemed that it was just written
var a = b;
However, bitwise 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 get fooled by a short cool record: Math.floor() works twice as fast (checked in FF3.6).

~~$x for rounding works in Pearl, and the time is the same as int($x) . Interesting in other languages? In Python, probably work too? Upd: did not work.

')

Source: https://habr.com/ru/post/89785/


All Articles