2012-03-13 19:51:14 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
|
2012-03-13 01:17:53 -04:00
|
|
|
#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)
|
|
|
|
{
|
2012-03-20 22:49:19 +01:00
|
|
|
#ifdef FE_INEXACT
|
|
|
|
int e;
|
2012-03-13 01:17:53 -04:00
|
|
|
|
2012-03-20 22:49:19 +01:00
|
|
|
e = fetestexcept(FE_INEXACT);
|
|
|
|
#endif
|
2012-03-13 01:17:53 -04:00
|
|
|
x = rintl(x);
|
2012-03-20 22:49:19 +01:00
|
|
|
#ifdef FE_INEXACT
|
|
|
|
if (!e)
|
|
|
|
feclearexcept(FE_INEXACT);
|
|
|
|
#endif
|
2012-03-13 01:17:53 -04:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
#endif
|