Reputation: 5525
It seems as if __STDC_IEC_559__
is insufficient to test for IEEE-754 compliance within the Apple ecosystem whcih leads to my question:
Which MacOS does support IEEE-754 full or at least the part with the binary32 and binary64 format and how to test for it with one or more C preprocessor macros?
Upvotes: 1
Views: 345
Reputation: 181199
It seems as if __STDC_IEC_559_ is insufficient to test for IEEE-754 compliance within the Apple ecosystem.
Yes and no. For one thing, it depends in part on your compiler, not just OS. For another, you need to be careful how you interpret the compiler's use of that macro.
As a preliminary matter, the __STDC_IEC_559__
macro (note: two trailing underscores) was introduced in C99. There are still compilers out there that do not conform to C99, at least by default. For it to make any sense to test __STD_IEC_559__
at all, then, you should first check whether the compiler claims to conform to C99 or later:
#if __STDC__ && __STDC_VERSION__ >= 19901L
// __STDC_IEC_559__ may tell us something ...
#endif
Supposing that you're working with a conforming implementation, you next need to appreciate that if an implementation defines __STDC_IEC_559__
to 1, it is asserting that it conforms to all the specifications in Annex F (C11) or Annex G (C99) of the standard, which cover not only floating-point data formats but also a fairly wide variety of specifications for operators and functions, including error bounds. The __STDC_IEC_559__
not being defined does not say anything about which part(s) are unsupported. In practice, almost everyone uses ISO 60559 data formats these days, but full ISO 60559 conformance is relatively rare.
Which MacOS does support IEEE-754 full or at least the part with the binary32 and binary64 format and how to test for it with one or more C preprocessor macros?
To the best of my knowledge, all versions of MacOS / OS X running on Intel chips support binary32 and binary64 as native floating-point formats. All the common compilers for those platforms map those native types to C float
and double
. There is no reliable, standard way to get the C preprocessor test that, however, because no standard macros provide that information, and actual testing would require floating-point math, which the preprocessor does not perform.
The closest you can come to testing the data formats via the preprocessor is to include float.h
and examine the macros that define the characteristics of types float
and double
. But even if these characteristics exactly match those of binary32 / binary64, that does not prove that the actual representations in memory take those forms. If you specifically care about the representation, then you'll need an external test program.
Upvotes: 4