mirror of
https://github.com/fluencelabs/musl
synced 2025-06-05 19:11:34 +00:00
old code saved/restored the fenv (the new code is only as slow as that when inexact is not set before the call, but some other flag is set and the rounding is inexact, which is rare) before: bench_nearbyint_exact 5000000 N 261 ns/op bench_nearbyint_inexact_set 5000000 N 262 ns/op bench_nearbyint_inexact_unset 5000000 N 261 ns/op after: bench_nearbyint_exact 10000000 N 94.99 ns/op bench_nearbyint_inexact_set 25000000 N 65.81 ns/op bench_nearbyint_inexact_unset 10000000 N 94.97 ns/op
26 lines
377 B
C
26 lines
377 B
C
#include <math.h>
|
|
#include <float.h>
|
|
|
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
|
long double nearbyintl(long double x)
|
|
{
|
|
return nearbyint(x);
|
|
}
|
|
#else
|
|
#include <fenv.h>
|
|
long double nearbyintl(long double x)
|
|
{
|
|
#ifdef FE_INEXACT
|
|
int e;
|
|
|
|
e = fetestexcept(FE_INEXACT);
|
|
#endif
|
|
x = rintl(x);
|
|
#ifdef FE_INEXACT
|
|
if (!e)
|
|
feclearexcept(FE_INEXACT);
|
|
#endif
|
|
return x;
|
|
}
|
|
#endif
|