fesetround Function

Sets the current rounding direction.

Attention: This function is implemented only by MPLAB XC32 C compilers.




int fesetround(int round);


the requested rounding direction

Return Value

This function returns zero if and only if the requested rounding direction was established.


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.


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