2012-03-13 01:17:53 -04:00
|
|
|
#include <fenv.h>
|
2012-03-13 19:51:14 +01:00
|
|
|
#include <math.h>
|
2012-03-13 01:17:53 -04:00
|
|
|
|
2012-03-20 22:49:19 +01:00
|
|
|
/* nearbyint is the same as rint, but it must not raise the inexact exception */
|
2012-03-13 01:17:53 -04:00
|
|
|
|
2012-03-20 22:49:19 +01:00
|
|
|
double nearbyint(double x)
|
|
|
|
{
|
|
|
|
#ifdef FE_INEXACT
|
2012-11-13 13:34:45 +01:00
|
|
|
#pragma STDC FENV_ACCESS ON
|
2012-03-20 22:49:19 +01:00
|
|
|
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 = rint(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;
|
|
|
|
}
|