1*f504f610SAugustin Cavalier #include "libm.h" 2*f504f610SAugustin Cavalier 3*f504f610SAugustin Cavalier #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 rintl(long double x)4*f504f610SAugustin Cavalierlong double rintl(long double x) 5*f504f610SAugustin Cavalier { 6*f504f610SAugustin Cavalier return rint(x); 7*f504f610SAugustin Cavalier } 8*f504f610SAugustin Cavalier #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 9*f504f610SAugustin Cavalier 10*f504f610SAugustin Cavalier static const long double toint = 1/LDBL_EPSILON; 11*f504f610SAugustin Cavalier rintl(long double x)12*f504f610SAugustin Cavalierlong double rintl(long double x) 13*f504f610SAugustin Cavalier { 14*f504f610SAugustin Cavalier union ldshape u = {x}; 15*f504f610SAugustin Cavalier int e = u.i.se & 0x7fff; 16*f504f610SAugustin Cavalier int s = u.i.se >> 15; 17*f504f610SAugustin Cavalier long double y; 18*f504f610SAugustin Cavalier 19*f504f610SAugustin Cavalier if (e >= 0x3fff+LDBL_MANT_DIG-1) 20*f504f610SAugustin Cavalier return x; 21*f504f610SAugustin Cavalier if (s) 22*f504f610SAugustin Cavalier y = x - toint + toint; 23*f504f610SAugustin Cavalier else 24*f504f610SAugustin Cavalier y = x + toint - toint; 25*f504f610SAugustin Cavalier if (y == 0) 26*f504f610SAugustin Cavalier return 0*x; 27*f504f610SAugustin Cavalier return y; 28*f504f610SAugustin Cavalier } 29*f504f610SAugustin Cavalier #endif 30