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_DOWNWARDRound down to the next lower integer.
FE_UPWARDRound up to the next greater integer.
FE_TONEARESTRound up or down toward whichever integer is nearest.
FE_TOWARDZERORound 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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access