6.5.14 fesetround Function
Sets the current rounding direction.
Include
<fenv.h>
Prototype
int fesetround(int round);
Argument
round
- the requested rounding direction
Return Value
This function returns zero if and only if the requested rounding direction was established.
Remarks
This function attempts to set the current floating-point rounding direction to that specified by the argument, which should be the value of the required rounding direction macro.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <fenv.h>
#include <stdio.h>
#include <assert.h>
int main(void)
{
int save_round, setround_ok;
volatile double x, y=1E30;
save_round = fegetround(); // save the rounding state
setround_ok = fesetround(FE_UPWARD);
assert(setround_ok == 0);
x = 1 / y;
printf("the small result rounded up is %.40f\n", x);
setround_ok = fesetround(FE_DOWNWARD);
assert(setround_ok == 0);
x = 1 / y;
printf("the small result rounded down is %.40f\n", x);
fesetround(save_round); // restore the rounding state
}
Example Output
the small result rounded up is 0.0000000000000000000000000000010000000001
the small result rounded down is 0.0000000000000000000000000000009999999999