I have discovered boost::math::changesign function, but cannot find a rationale of using it. The Internet keeps radio silence and even Boost itself barely uses it.
My thoughts were:
- There are some values where
-x
is forbidden. - To avoid compiler bugs.
- Faster at runtime.
However:
- It seems to be a valid operation on any value, at least for IEEE 754.
- The different compilers/platforms I have tried generate bit-identical results for
changesign
and-x
https://godbolt.org/g/4ttsfW. - Current GCC and Clang produces the same machine codes for both methods, the older ones (and any MSVC) generate a way longer assembly for
changesign
https://godbolt.org/g/nT6j26.