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:
- Read its documentation.
- Examine its source code.
- Test it (which is, of course, difficult when only exhaustive testing can be conclusive).
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:
- Intermediate arithmetic is performed with more precision than the nominal type. E.g., expressions that use
double
values may be calculated with long double
precision.
sqrt
does not return a correctly rounded value in every case.
- Other math library routines return values that may be slightly off (a few ULP) from the correctly rounded results. (In fact, nobody has implemented all the math routines recommended in IEEE 754-2008 with both guaranteed correct rounding and guaranteed bound run time.)
- Subnormal numbers (tiny numbers near the edge of the floating-point format) may be converted to zero instead of handled as specified by IEEE 754.
- Conversions between decimal numerals (e.g.,
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.
- Only round-to-nearest mode is supported; the other rounding modes specified in IEEE 754 are not supported. Or they may be available for simple arithmetic but require using machine-specific assembly language to access. Standard math libraries (
cos
, log
, et cetera) rarely support other rounding modes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…