Handling floating-point constant folding and rounding
By default, the compiler replaces most operations involving constant operands
with their result at compile time. This process is known as constant folding. Additional folding opportunities may occur with optimization
or with the -qnostrict option. The result of a floating-point operation folded at compile
time normally produces the same result as that obtained at execution time,
except in the following cases:
- The compile-time rounding mode is different from the execution-time rounding
mode. By default, both are round-to-nearest; however, if your program changes
the execution-time rounding mode, to avoid differing results, do either of
the following:
- Expressions like a+b*c are partially or fully evaluated at compile time. The
results might be different from those produced at execution time, because b*c might be rounded before being
added to a, while the runtime multiply-add instruction
does not use any intermediate rounding. To avoid differing results, do either
of the following:
- Suppress the use of multiply-add instructions, by compiling with the -qfloat=nomaf option.
- Suppress folding, by compiling with the -qfloat=nofold option.
- An operation produces an infinite or NaN result. Compile-time folding
prevents execution-time detection of an exception, even if you compile with
the -qflttrap option. To avoid missing these exceptions,
suppress folding with the -qfloat=nofold option.
Related information