X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fmath%2Fnearbyint.c;fp=src%2Fmath%2Fnearbyint.c;h=781769fba89c8850933997505bf5d943ea6fcbcd;hp=0000000000000000000000000000000000000000;hb=b69f695acedd4ce2798ef9ea28d834ceccc789bd;hpb=d46cf2e14cc4df7cc75e77d7009fcb6df1f48a33 diff --git a/src/math/nearbyint.c b/src/math/nearbyint.c new file mode 100644 index 00000000..781769fb --- /dev/null +++ b/src/math/nearbyint.c @@ -0,0 +1,20 @@ +#include +#include "libm.h" + +/* +rint may raise inexact (and it should not alter the fenv otherwise) +nearbyint must not raise inexact + +(according to ieee754r section 7.9 both functions should raise invalid +when the input is signaling nan, but c99 does not define snan so saving +and restoring the entire fenv should be fine) +*/ + +double nearbyint(double x) { + fenv_t e; + + fegetenv(&e); + x = rint(x); + fesetenv(&e); + return x; +}