update FastMath to use std::frexp and std::ldexp #333
Labels
bug
Something isn't working
floating-point
issue with floating-point roundoff error
priority:high
high priority
The old implementation of the "not-quite-transcendental" functions in FastMath.hpp used magic numbers and
reinterpret_cast
to do the low-level bitwise manipulation.Unfortunately, while it worked on all of our current platforms and compilers, the result of
reinterpret_cast
is undefined behavior, so it is better to use the C++ standard library functionsstd::frexp
andstd::ldexp
to manipulate the mantissa and exponent. These are defined in a way that their results are independent of the floating point representation, but can be efficiently implemented with bitwise operations on systems that use IEEE floating-point numbers.This is done in the new implementation of these functions in singularity-eos: https://github.com/lanl/singularity-eos/blob/2ea3957cc18cd4709b926f415dd68a8d4daf8821/singularity-eos/base/fast-math/logs.hpp#L38C3-L38C3
The text was updated successfully, but these errors were encountered: