diff --git a/src/s_round.c b/src/s_round.c index ec758fc..d1250b4 100644 --- a/src/s_round.c +++ b/src/s_round.c @@ -34,19 +34,21 @@ DLLEXPORT double round(double x) { double t; + uint32_t hx; - if (!isfinite(x)) - return (x); + GET_HIGH_WORD(hx, x); + if ((hx & 0x7fffffff) == 0x7ff00000) + return (x + x); - if (x >= 0.0) { + if (!(hx & 0x80000000)) { t = floor(x); if (t - x <= -0.5) - t += 1.0; + t += 1; return (t); } else { t = floor(-x); if (t + x <= -0.5) - t += 1.0; + t += 1; return (-t); } }