updates to s_round.c from FreeBSD

This commit is contained in:
Jeff Bezanson 2013-12-19 17:52:23 -05:00
parent 3566e32d84
commit 9ca11f20c6
1 changed files with 7 additions and 5 deletions

View File

@ -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);
}
}