
Pfligersdorffer, Christian wrote:
Bo Peng on Tuesday, September 02, 2008 5:09 PM:
I do not think I want to be the one who tries to satisfy everybody. That's a daunting task... I will use your version of portable binary archive as long as there is a way to test its compatibility with the underlying system... Just something like "whoops, this system is not IEEE754 compatible so archives created on this system will not be portable".
It's not straight forward to do such a test but I will have a look at it for the next release. Johan Rade does a classication of floating point formats in his fp_utilities. I'll see if I can use that.
In practice almost all platforms have float and double implementations that are enough IEEE 754 compliant to make it ok to save the bytes and load them again. The only exceptions I know of are: 1. some compilers have a setting where denormals, infinity and Nan are not used 2. on VMS there is still support for the VAX floating point format Condition 1 can be detected by numeric_limits<T>::has_denorm etc. Condition 2 can be detected as follows #if defined(__vms) && defined(__DECCXX) && !__IEEE_FLOAT Also note that the bit patterns that represent quiet NaN on one platform can represent signaling NaN on other platforms. But very few C++ developers seem to care about the difference between quiet and signaling NaN. And forget about portable binary serialization of long double (unless you want to do a lot of work). --Johan