The compiler attempts to perform as much floating-point arithmetic as possible at compile time. Floating-point operations with constant operands are folded, replacing the operation with the result calculated at compile time. When the -O option is used, more folding might occur than when optimization is not enabled.
All compile-time folding of floating-point computations can be suppressed using the float=nofold option. Alternatively, the IEEE rounding mode used in compile-time arithmetic can be controlled using the -y options.
Compile-time floating-point arithmetic can have two effects on program results:
In general, code that affects the rounding mode at run time should be compiled with the -y option that matches the rounding mode intended at run time. For example, when the following program:
main () { float x, y; int i; x = 1.0/3.0; i = *(int *)&x; printf("1/3 = %.8x\n", i); x = 1.0; y = 3.0; x = x/y; i = *(int *)&x; printf("1/3 = %.8x\n", i); }
is compiled with:
xlC -yz -qfloat=rndsngl
the expression 1.0/3.0 is folded by the compiler at compile time into a double-precision result. This result is then converted to single precision and then stored in float x. The float=nofold option can be specified to suppress all compile-time folding of floating-point computations. The -yz option only affects compile-time rounding of floating-point computations, but does not affect runtime rounding. The code fragment:
x = 1.0; y = 3.0; x = x/y;
is evaluated at run time in single precision. Here, the default runtime rounding of "round to nearest" is still in effect and takes precedence over the compile-time specification of "round to zero" (-yz).
Note: The -y option does not specify the runtime rounding mode.
Floating-Point Compiler Options
Rounding Mode Restrictions