At 3/23/16 06:14 PM, Diki wrote: This might be faster, but I am far too lazy to find out:
return Math.sign(n) === 1 && parseInt(n) === n;
Still doesn't require 10 dependencies to work. The future is now!
Haxe optimized my custom floor (pos or neg):
return n > 0 ? Std.int(n) : Std.int(n - 1);
on js to
return n > 0 ? n|0 : (n-1)|0;
That obviously doesn't deal with NaN, inf, floats bigger than MAX_SIGNED_INT, and probably other things. But yeah, 20x faster than Math.floor. But it's not nearly as dramatic of a speedup on the other targets, 2x faster on flash, a little bit on cpp, and worse on neko for some ghastly reason.
Std.int on neko is slower than Math.floor, so there's not a lot I can do there anyway
For some of these, the function call to Math.floor is more expensive than inlining the math.