5 ms·
I completely agree about using floor() for readability. That said, could we fix the negative value issue as follows and still see performance benefits (don't h
by tomkinstinch 16y ago
I completely agree about using floor() for readability.
That said, could we fix the negative value issue as follows and still see performance benefits (don't have the time to test at the moment)?
x = x < 0 ? (0|x) - 1 : 0|x;
---or maybe---
x |= 0;
x = x < 0 ? x-1 : x;
---or possibly---
x |= 0;
x = ((x ^ (x >> 31)) - (x >> 31)) - 1;
If the above bitwise operation were wrapped in a helper function, would we still see any performance gain?