Am 22.08.22 um 02:11 schrieb Proton:
Hi Matt, I haven't tried whether clang's bit_cast supports bit fields. There is a problem with your simple implementation: Memory size for long double/float80 can be 10/12/16 bytes depending on platform or compiler option. You didn't take that into account, so bit_cast then fails.
That's why I'm working on extended structures for the bitrepresentation for float-types, so that unusual or machine-specific types can also be mapped. These then also include manipulating the individual components and/or checking for special values. For the concrete implementations it would be advantageous to have a stable bit_cast; otherwise I can only use explicit bitpatterns and hope they are (ieee) compatible.
This approach has other advantages. These extended structures always deliver correct results, even if the compiler option fast-math/finite-math or something similar is set. This can be used to implement various requirements, e.g. isnan/isinf: - isnan/isinf -> default - isnan_stable/isinf_stable -> correct results also with fast/finite-math etc
This can be very useful when implementing math functions.
Best, Gero
Gero,
What platform does this fail on? I have provided multiple macro enabled definitions for the bit patterns of long doubles on major architectures.
e.g. on x86 gcc (https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/x86-Options.html#x86-Options): x86_64 sizeof(long double) == 16 x86_32 sizeof(long double) == 12 This can also be changed with compiler flags, eg with gcc -m96bit-long-double -m128bit-long-double and/or -mlong-double-64 -mlong-double-80 -mlong-double-128
Have you run into issues with the implementations of isnan or isinf? We provide a version of fpclassify (https://www.boost.org/doc/libs/1_80_0/boost/math/special_functions/fpclassif... https://www.boost.org/doc/libs/1_80_0/boost/math/special_functions/fpclassif...) that yields stable results regardless of the compiler flag like you are looking for.
But fpclassify is an if-else-cascade and not a direct and therefore fast test.
Matt
Gero