Sets the rounding direction in the floating-point environment
#include <fenv.h> int fesetround ( int round );
The fesetround( ) function sets the current rounding direction in the program's floating-point environment to the direction indicated by its argument. On success the function returns 0. If the argument's value does not correspond to a rounding direction, the current rounding direction is not changed.
Recognized values of the argument are given by macros in the following list, defined in fenv.h as integer constants. A given implementation may not define all of these macros if it does not support the corresponding rounding direction, and may also define macro names for other rounding modes that it does support.
The function returns 0 if successful; a nonzero return value indicates that an error occurred.
/* * Save, set, and restore the rounding direction. * Report an error and abort if setting the rounding direction fails. */ #pragma STDC FENV_ACCESS ON int prev_rounding_dir; int result; prev_rounding_dir = fegetround( ); result = fesetround( FE_TOWARDZERO ); /* ... perform a calculation that requires rounding toward 0 ... */ fesetround( prev_rounding_dir ); #pragma STDC FENV_ACCESS OFF
See also the example for fmod( ) in this chapter.