ucis8w
Last Updated: February 25, 2016
·
922
· ooflorent

JavaScript fast-floor

Use the double NOT bitwise operator to perform a fast-floor.

Math.floor(123.456) // => 123
~~123.456 // => 123

Pro tip: Be careful with negative numbers!

Math.floor(-123.456) // => 124
~~-123.456 // => 123

1 Response
Add your response

1206

Interesting. It does seem faster, to a degree:
http://jsperf.com/math-floor-no-loop & http://jsperf.com/math-floor

over 1 year ago ·