3

I'd like that an application would be able to know if it's running on a system whose "long double" type is a synonym for "double", or a true 128bit IEEE quad precision, or an 80bit Intel extended format, or a "double-double".

Is it possible to check this at runtime? How?

cesss
  • 852
  • 1
  • 6
  • 15
  • 1
    does `sizeof` meet your requirements? – M.M Mar 22 '16 at 20:12
  • I don't think so: sizeof(long double) will return 16 for true 128bit IEEE, for "double double", and for 80bit Intel on some systems. However, it would allow to check if "long double" is a synonym for double on the system. – cesss Mar 22 '16 at 20:40
  • 5
    I don't have a way to test all formats mentioned, so won't write an answer. You should be able to distinguish these formats by computing `1 + eps - 1`, for appropriate values of `eps`. Chose `eps` such that the result is zero for the narrower format, but `eps` for the next wider format. E.g. with `eps = 0x1.0p-120`, `1 + eps` is representable as a double-double, but rounds to 1 for a 128-bit IEEE-754 `binary128` quadruple precision format. – njuffa Mar 22 '16 at 22:05
  • Do you have a language in mind? e.g., [`std::numeric_limits`](http://en.cppreference.com/w/cpp/types/numeric_limits) in `` for C++11, makes this relatively easy. – Brett Hale Mar 23 '16 at 11:04
  • @BrettHale: Language can be either C or C++, but I prefer to avoid a version requirement, such as C++11. Anyway, the definitions in available for almost every C compiler can provide the same aid. – cesss Mar 23 '16 at 11:45
  • @njuffa: Thanks a lot, the epsilon trick, combined with sizeof() and perhaps some binary magic, can be everything I need. – cesss Mar 23 '16 at 11:47

0 Answers0