I want to test the following things on my target board:
What are the ways in which i can test it with a simple C program.
No simple test exists.
The overwhelming majority of systems today use IEEE-754 formats for floating-point. However, most C implementations do not fully conform to IEEE 754 (which is identical to IEC 60559) and do not set the preprocessor identifier __STDC_IEC_559__
. In the absence of this identifier, the only way to determine whether a C implementation conforms to IEEE 754 is one or a combination of:
In many C implementations and software applications, the deviations from IEEE 754 can be ignored or worked around: You may write code as if IEEE 754 were in use, and much code will largely work. However, there are a variety of things that can trip up an unsuspecting programmer; writing completely correct floating-point code is difficult even when the full specification is obeyed.
Common deviations include:
double
values may be calculated with long double
precision.sqrt
does not return a correctly rounded value in every case.3.1415926535897932384626433
in the source code) and binary floating-point formats (e.g., the common double
format, IEEE-754 64-bit binary) do not always round correctly, in either conversion direction.cos
, log
, et cetera) rarely support other rounding modes.In C99, you can check for __STDC_IEC_559__
:
#ifdef __STDC_IEC_559__
/* using IEEE-754 */
#endif
This is because the international floating point standard referenced by C99 is IEC 60559:989 (IEC 559 and IEEE-754 was a previous description). The mapping from the C language to IEC 60559 is optional, but if in use, the implementation defines the macro __STDC_IEC_559__
(Appendix F of the C99 standard), so you can totally rely on that.
Another alternative is to manually check if the values in float.h
, such as FLT_MAX
, FLT_EPSILON
, FLT_MAX_10_EXP
, etc, match with the IEEE-754 limits, although theoretically there could be another representation with the same values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With