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