Round with bitwise
by alex_o
JavaScript
alert( ~~5.345 ); // 5
alert( 5.345 ^ 0 ); // 5
alert( 9.1 + 1.2 ^ 0 ); // 10 first we sum up, then round
//But!
alert(Math.floor(2777788881.2)); // 2777788881
alert( 2777788881.2 ^ 0); // -1517178415
alert(Math.floor(-213.4)); // -214
alert(-213.4 ^ 0); // -213
alert(Math.floor(NaN)); // NaN
alert(NaN ^ 0); // 0