While searching for a way to do a faster ceil
operator than ceil
itself, I came upon this:
var ceilX = (X + 1) >> 0
Which does a bit of bitwise magic to shave off the decimal, but ultimately fails to do a correct ceil
operation because (1 + 1) >> 0 === 2
, while ceil(1) === 1.
There's a different question on how to do this here, but the line of thought got me wondering if there's a way to add a number that's baaaaarely less than 1 to a value and then use the bitwise shift to round it. This seems to me like it should work for everything that can be expressed as a 32-bit number, but I'm not sure how to get the number that's really close to 1. In the name of pointless micro optimization, is there a good way of doing this?