blob: 82852492f8108b875fa6c588af96aecf358475b9 [file] [log] [blame]
nsz9560b6b2012-03-13 19:51:14 +01001#include <math.h>
2#include <float.h>
3
Rich Felkerb69f6952012-03-13 01:17:53 -04004#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
5long double nearbyintl(long double x)
6{
7 return nearbyint(x);
8}
9#else
10#include <fenv.h>
11long double nearbyintl(long double x)
12{
nsz91c28f62012-03-20 22:49:19 +010013#ifdef FE_INEXACT
Szabolcs Nagy033a9d62012-11-13 13:34:45 +010014 #pragma STDC FENV_ACCESS ON
nsz91c28f62012-03-20 22:49:19 +010015 int e;
Rich Felkerb69f6952012-03-13 01:17:53 -040016
nsz91c28f62012-03-20 22:49:19 +010017 e = fetestexcept(FE_INEXACT);
18#endif
Rich Felkerb69f6952012-03-13 01:17:53 -040019 x = rintl(x);
nsz91c28f62012-03-20 22:49:19 +010020#ifdef FE_INEXACT
21 if (!e)
22 feclearexcept(FE_INEXACT);
23#endif
Rich Felkerb69f6952012-03-13 01:17:53 -040024 return x;
25}
26#endif