X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmath%2Fround.c;h=130d58d2571e77cc15a67b355010e11c5ebebe91;hb=0ce946cf808274c2d6e5419b139e130c8ad4bd30;hp=4b38d1fdbb2adca6f1f89a8ff86dc29e9206f272;hpb=79ca86094d70f43252b683c3a3ccb572d462cf28;p=musl diff --git a/src/math/round.c b/src/math/round.c index 4b38d1fd..130d58d2 100644 --- a/src/math/round.c +++ b/src/math/round.c @@ -1,5 +1,12 @@ #include "libm.h" +#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 +#define EPS DBL_EPSILON +#elif FLT_EVAL_METHOD==2 +#define EPS LDBL_EPSILON +#endif +static const double_t toint = 1/EPS; + double round(double x) { union {double f; uint64_t i;} u = {x}; @@ -12,10 +19,10 @@ double round(double x) x = -x; if (e < 0x3ff-1) { /* raise inexact if x!=0 */ - FORCE_EVAL(x + 0x1p52); + FORCE_EVAL(x + toint); return 0*u.f; } - y = (double)(x + 0x1p52) - 0x1p52 - x; + y = x + toint - toint - x; if (y > 0.5) y = y + x - 1; else if (y <= -0.5)