How are c++11 boost libraries dealing with these compiler issues? I got some options in mind: — Implement everything using custom detections, this will work in every compiler, but it will run slower for everyone too. — Finding a compiler with the support, implementing the library using the FENV, and assuming compilers will support it when the library is finished and reviewed. — Detect somehow the FENV pragma was not processed and have 2 implementations. No idea how to detect something like this.
Had someone dealt with similar problem already? Is there a common approach?
No, but you've had some good suggestions, and I would just add my +1
that FENV is unlikely to be very widely available due to the issues
outlined.
Some other resources that may help you:
* If you're targeting C++11 then you can reasonably rely on
std::isfinite and friends.
* If as suggested you want to try bit-fiddling to get the status of an
FP value, then that code is already in Boost.Math (see fpclassify.hpp
and includes thereof) and you can steal as required ;-) Obviously any
software solution will be *much* slower than getting the hardware to
raise an exception for you.
* When it comes to testing, libs/multiprecision/test/test_arithmetic.hpp
has a template function "test_arithmetic" that's designed to test every
conceivable arithmetic operator (and permutations thereof).
* In fact it occurs to me that you could implement what you had in mind
in about 10 minutes using Boost.Multiprecision - albeit in a more
heavyweight and less flexible manner than a dedicated solution.... in
fact I've attached sample code below. Given that we known that the
"abstraction overhead" of boost::multiprecision::number with
arithmetic_backend is very small, this might make a quick/easy/dirty way
to test various FP-testing methods?
HTH, John.
Here's the test code:
#include