Search code examples
c++floating-pointieee-754standards-complianceextended-precision

Function that returns whether the floating-point type is fully compliant to IEEE-754?


I would like to write a function that checks that float, double or long double are fully compliant to the IEEE-754 format. I mean:

I thought that std::numeric_limits<T>::is_iec559 was corresponding to that, but it returns true for long double on my Linux 64-bits where sizeof(long double) = 16 bytes but internally encoded in a 80-bit Intel format. So how to do that?


Solution

  • If std::numeric_limits<T>::is_iec559 is true then T adheres to the standard.

    If the system uses 80-bit for its internal registers this is ok as long as the final rounded result is the closest to a reference result where an infinite number of bits is used. That is, adding or removing one ulp will get you away from the reference.

    It's hard to check this by running all possible operations with all representable numbers and compare against a reference that uses many bits.

    You need to have confidence on std::numeric_limits and the library implementing it.