DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Floating point operations

Rounding control

The floating point arithmetic provides four rounding modes that affect the result of most floating point operations. (These modes are defined in the header ieeefp.h):

FP_RN round to nearest representable number, tie -> even
FP_RP round toward plus infinity
FP_RM round toward minus infinity
FP_RZ round toward zero (truncate)

You can check the current rounding mode with the function

   fp_rnd fpgetround(void); /* return current rounding mode */
You can change the rounding mode for floating point operations with the function:
   fp_rnd fpsetround(fp_rnd); /* set rounding mode, */
                              /* return previous */
(fp_rnd is an enumeration type with the enumeration constants listed and described above. The values for these constants are in ieeefp.h.)


NOTE: These examples, such as the one directly above, illustrate function prototypes. For further information on function prototypes, see ``Function definitions'' in ``C language compilers''.

The default rounding mode is round-to-nearest. In C and FORTRAN (F77), floating point to integer conversions are always done by truncation, and the current rounding mode has no effect on these operations.

For more information on fpgetround and fpsetround, see fpgetround(S).


Next topic: Exceptions, sticky bits, and trap bits
Previous topic: NaNs and infinities

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005