fegetround Function

Gets the current rounding direction.

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

Include

<fenv.h>

Prototype

int fegetround(void);

Return Value

This function returns the a value representing the current floating-point rounding direction, which can be compared to the rounding-direction macros.

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