Conversation
|
|
||
| return result; | ||
| const auto t = std::trunc(value); | ||
| if (const auto diff = std::abs(value - t); diff > 0.5f || (diff == 0.5f && !is_even(t))) |
There was a problem hiding this comment.
Wouldn't it be less branching to have two if cases than using abs? Or is abs constexpr and the compiler can optimise all this out?
There was a problem hiding this comment.
The abs (or fabs in C) is recognized and replaced with __builtin_abs or something. This just masks out the sign bit: x & 0x7fffffff.
Codecov Report
@@ Coverage Diff @@
## master #504 +/- ##
==========================================
- Coverage 99.69% 99.69% -0.01%
==========================================
Files 54 54
Lines 17198 17180 -18
==========================================
- Hits 17146 17128 -18
Misses 52 52 |
|
I also have another implementation based on bit manipulation which looks to be faster but I did not perform proper benchmarks yet. We may wait with that for the next release until having more FP test cases. |
05b277f to
2f9edfe
Compare
2f9edfe to
db4421c
Compare
|
I'm checking some additional options because there are some performance regressions. |
This implementation does not need to modify rounding direction to work correctly under any rounding direction.
4e072bd to
c413a4c
Compare
|
GCC: GCC+LTO: So not really significant difference (none of the benchmarks uses this instruction). The change is not driven by performance anyway. When marking the function with |
c413a4c to
4e42e95
Compare
This implementation does not need to modify rounding direction to work
correctly under any rounding direction.