rework langinfo code for ABI compat and for use by time code
[musl] / src / math / nearbyintl.c
index b58527c..8285249 100644 (file)
@@ -1,4 +1,6 @@
-#include "libm.h"
+#include <math.h>
+#include <float.h>
+
 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
 long double nearbyintl(long double x)
 {
@@ -8,11 +10,17 @@ long double nearbyintl(long double x)
 #include <fenv.h>
 long double nearbyintl(long double x)
 {
-       fenv_t e;
+#ifdef FE_INEXACT
+       #pragma STDC FENV_ACCESS ON
+       int e;
 
-       fegetenv(&e);
+       e = fetestexcept(FE_INEXACT);
+#endif
        x = rintl(x);
-       fesetenv(&e);
+#ifdef FE_INEXACT
+       if (!e)
+               feclearexcept(FE_INEXACT);
+#endif
        return x;
 }
 #endif