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: The examples in this section, such as the one directly above, illustrate function prototypes. For further information on function prototypes, see ``Function definitions''.

The default rounding mode is round-to-nearest. In C, 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

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003