blog
Tag Archive for floor at Jozef Chúťka's blog
January 10, 2011
Faster floor, round, ceil for ActionScript
It is always nice to add some speed boost to your performance critical algorithms. Making some native Math function’s alternatives perform up to 8 times faster is possible. Lets have a look at the basic ones Math.floor(), Math.round(), Math.ceil():
faster alternative for Math.floor()
var ni:int = n;
return (n < 0 && n != ni) ? ni - 1 : ni;faster alternative for Math.round()
return n < 0 ? n + .5 == (n | 0) ? n : n - .5 : n + .5;faster alternative for Math.ceil()
var ni:int = n;
return (n >= 0 && n != ni) ? ni + 1 : ni;