FLT_EVAL_METHOD .
C allows intermediate FP calculations on higher / wider types depending on FLT_EVAL_METHOD . Therefore, when wider types are used and the code flow is different, albeit mathematically equal, slightly different results may occur.
With the exception of assignment and casting (which removes all additional range and accuracy), the values obtained by operators with floating operands and values subject to ordinary arithmetic conversions and floating constants are evaluated in a format whose range and accuracy may be greater than what is required by type. The use of evaluation formats is characterized by the implementation-specific value FLT_EVAL_METHOD :
-1. indefinable;
0. evaluate all operations and constants only by range and type accuracy; 1. Evaluate operations and constants of type float and double the range and precision of a double type, evaluate long dual operations and constants in the range and precision of a long double type.
2. Evaluate all operations and constants in the range and accuracy of the long double type.
C11dr §5.2.4.2.2 9
[change]
@Pascal Cuoq has a helpful commentary about the veracity of FLT_EVAL_METHOD . In any case, FP code optimized for different code paths can present different results. This can happen if FLT_EVAL_METHOD != 0 or the compiler does not comply with strict compliance.
Regarding the details of the message: the operation X*Y + Z , performed in 2 operations * , and then + can be contrasted with fma() , which "calculates (x × y) + z, is rounded as one triple: they calculate value (as if) to infinite precision and rounded once to the format of the result in accordance with the current rounding mode. " C11 §7.12.13.1 2. Another candidate for a difference in results may be caused by applying "fma" to the line e=(c/d)*(ba)+a;
source share