Name
fesetround
Synopsis
Sets the rounding direction in the floating-point environment
#include <fenv.h> intfesetround
( intround
);
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.
FE_DOWNWARD
Round down to the next lower integer.
FE_UPWARD
Round up to the next greater integer.
FE_TONEAREST
Round up or down toward whichever integer is nearest.
FE_TOWARDZERO
Round positive values downward and negative values upward.
The function returns 0 if successful; a nonzero return value indicates that an error occurred.
Example
/* * 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. ...
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.