F.0 Scope
An implementation that defines __STDC_IEC_559__ conforms to this annex. An implementation that does not conform shall not define the macro, and shall document the floating-point behavior it does provide under Annex C clause C.5.
Nothing in this annex is optional for an implementation that claims it. The alternative to claiming it is not claiming it.
F.1 Formats
Where the target supports them:
floatis the IEC 60559 binary32 format,doubleis the IEC 60559 binary64 format.
long double is one of binary64, binary128, the 80-bit extended format, a double-double format, or another format the implementation documents. A conforming implementation shall name the format it uses.
The exact-width floating types are not part of this edition. A program that needs a specific format tests FLT_MANT_DIG and the related macros of clause 7.2.5.
F.2 Operations
Addition, subtraction, multiplication, division, remainder, square root, and conversion between supported formats are correctly rounded, as IEC 60559 requires.
The +, -, *, and / operators of clause 6.5 map to the corresponding IEC 60559 operations. sqrt maps to the IEC 60559 square root.
Conversion from an integer type to a floating type is correctly rounded. Conversion from a floating type to an integer type truncates toward zero, and traps where the result is not representable, under clause 6.3.1.4.
Contraction. An implementation shall not contract an expression into an operation with different rounding unless #pragma STDC FP_CONTRACT is ON. The default is OFF. See clause 5.1.2.3.
F.3 Special Values
Infinities.
Division of a nonzero finite value by zero produces an infinity of the appropriate sign and raises the divide-by-zero exception. Floating division by zero does not trap, in contrast with integer division by zero. The two operations are different, and this edition treats them differently because IEC 60559 defines a result for one and no result exists for the other.
NaNs.
A NaN compares unequal to everything, including itself. Therefore:
x != xis true whenxis a NaN,- every relational operator yields 0 when either operand is a NaN,
isnan(x)is the readable spelling and programs should use it.
A NaN used as a condition is true, because it is not numerical zero. See clause 6.5.0.5.
Converting a NaN to an integer type causes a defined trap, under clause 6.3.1.4.
Signed zero.
Positive and negative zero compare equal. signbit distinguishes them. Default initialization of a floating object produces positive zero, under clause 6.7.9.2.
Subnormals.
Subnormal values are supported. An implementation that provides a flush-to-zero mode shall not enable it by default, and shall document how a program enables it. A flush-to-zero mode is not conforming to this annex while it is enabled.
F.4 Exceptions
The five IEC 60559 exceptions are raised as that standard requires: invalid operation, division by zero, overflow, underflow, and inexact.
Raising an exception sets the corresponding flag. It does not trap and does not stop execution. A program inspects the flags through <fenv.h>, and shall enable #pragma STDC FENV_ACCESS before doing so. See clause 7.2.7.
An implementation may provide trapping on floating-point exceptions as a documented extension. It shall be off by default, because IEC 60559 semantics are flag-based and a program written against them expects to continue.
F.5 Rounding
The default rounding direction is round to nearest, ties to even.
A program changes the rounding direction with fesetround, having enabled #pragma STDC FENV_ACCESS.
Translation-time evaluation of floating constant expressions uses the default rounding direction, regardless of what the program later selects at execution time. Clause 6.6.3 requires the implementation to document any resulting difference between a folded expression and its runtime equivalent.
F.6 Expression Evaluation
FLT_EVAL_METHOD describes the format in which floating expressions are evaluated:
| Value | Meaning |
|---|---|
| 0 | each operation is evaluated in the format of its type |
| 1 | float operations are evaluated as double |
| 2 | float and double operations are evaluated as long double |
An implementation shall report what it actually does. Reporting 0 while evaluating in a wider format is not conforming, because a program cannot then predict any result.
An implementation shall not present a wider intermediate result where the narrower type was required by an assignment, a cast, or a return. See clause 6.3.1.5.
F.7 Mathematical Functions
The functions of <math.h> follow the ISO C99 Annex F specification of their special-value behavior, including the results for infinities, NaNs, and signed zeros.
Error reporting follows clause 7.2.6: errno is set, and the corresponding exception is raised. math_errhandling has the value MATH_ERRNO | MATH_ERREXCEPT on an implementation conforming to this annex.
F.8 Relationship to the Rest of the Edition
Two rules of the edition interact with this annex, and both are deliberate.
Floating arithmetic is never silently replaced by integer arithmetic. An implementation shall not evaluate a floating expression using integer operations in a way that changes the result, including the sign of a zero and the presence of a NaN.
Optimization does not define semantics. The rules of clause 4.7 apply here as everywhere. An implementation shall not assume that a value is not a NaN, shall not assume that an operation does not overflow, and shall not reassociate floating operations, unless the program has enabled contraction or the implementation can prove the transformation exact.
An implementation may offer a fast-math mode. That mode does not conform to this annex, shall not define __STDC_IEC_559__, and shall be off by default. See clause 4.8.1.