Here's a fairly extreme nerd snipe: what does this do and why? Apologies to those who just can't wrap their head around it. ((x + 0.24999994) + 0.25000006).floor()
So that's the basic functionality, but it goes much deeper. Why not the simple, obvious approach?
-
-
Works even for denormals?
-
I believe so, but please check it. There is an astonishing amount of subtlety around floating point.
- 3 more replies
New conversation -
-
-
Not sure which approach you think is the simple obvious one :) Could change the hardware rounding mode to FE_UPWARD, but then you have to save/restore it (else possibly break other code), and I'm not sure of the perf implications—might cause some float pipeline flush?
-
Alternatively, could write something like 'if (x - floor(x) == 0.5) return ceil(x);', but your version has the advantage of being branchless.
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.