nearbyint.c 332 B

1234567891011121314151617181920
  1. #include <fenv.h>
  2. #include <math.h>
  3. /* nearbyint is the same as rint, but it must not raise the inexact exception */
  4. double nearbyint(double x)
  5. {
  6. #ifdef FE_INEXACT
  7. #pragma STDC FENV_ACCESS ON
  8. int e;
  9. e = fetestexcept(FE_INEXACT);
  10. #endif
  11. x = rint(x);
  12. #ifdef FE_INEXACT
  13. if (!e)
  14. feclearexcept(FE_INEXACT);
  15. #endif
  16. return x;
  17. }