781769fba89c8850933997505bf5d943ea6fcbcd
[musl] / src / math / nearbyint.c
1 #include <fenv.h>
2 #include "libm.h"
3
4 /*
5 rint may raise inexact (and it should not alter the fenv otherwise)
6 nearbyint must not raise inexact
7
8 (according to ieee754r section 7.9 both functions should raise invalid
9 when the input is signaling nan, but c99 does not define snan so saving
10 and restoring the entire fenv should be fine)
11 */
12
13 double nearbyint(double x) {
14         fenv_t e;
15
16         fegetenv(&e);
17         x = rint(x);
18         fesetenv(&e);
19         return x;
20 }