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()
-
-
-
Replying to @TimSweeneyEpic
So that's the basic functionality, but it goes much deeper. Why not the simple, obvious approach?
2 replies 0 retweets 0 likes -
Replying to @raphlinus @TimSweeneyEpic
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?
1 reply 0 retweets 0 likes -
Alternatively, could write something like 'if (x - floor(x) == 0.5) return ceil(x);', but your version has the advantage of being branchless.
1 reply 0 retweets 0 likes
I think of `floor(x + 0.5)` as the obvious approach to implement "round away from 0", but it's incorrect for the value an epsilon below 0.5 and for medium-large integers. Being branchless was a goal, I want this to auto-vectorize.
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.