summaryrefslogtreecommitdiffstats
path: root/libm/upstream-freebsd/lib/msun/src/s_roundf.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-10-10 10:21:43 -0700
committerElliott Hughes <enh@google.com>2014-10-10 10:21:43 -0700
commit14538ca75ef3d0edc8fb86e332d79a4913238cb6 (patch)
treefc02d348aa55a1a9191d4edd9619583ee742b5bb /libm/upstream-freebsd/lib/msun/src/s_roundf.c
parent8dd3b65f2dd63df1baa83285f607cf110f21c27c (diff)
downloadbionic-14538ca75ef3d0edc8fb86e332d79a4913238cb6.zip
bionic-14538ca75ef3d0edc8fb86e332d79a4913238cb6.tar.gz
bionic-14538ca75ef3d0edc8fb86e332d79a4913238cb6.tar.bz2
Catch up on upstream's round/roundf/roundl.
Not sure how we missed these, but better late than never... Change-Id: Ib08d1bb6e340a1907cbeb1cbe220e33f70642bdc
Diffstat (limited to 'libm/upstream-freebsd/lib/msun/src/s_roundf.c')
-rw-r--r--libm/upstream-freebsd/lib/msun/src/s_roundf.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/libm/upstream-freebsd/lib/msun/src/s_roundf.c b/libm/upstream-freebsd/lib/msun/src/s_roundf.c
index 952e8e7..e7e2eb9 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_roundf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_roundf.c
@@ -27,25 +27,28 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <math.h>
+#include "math.h"
+#include "math_private.h"
float
roundf(float x)
{
float t;
+ uint32_t hx;
- if (!isfinite(x))
- return (x);
+ GET_FLOAT_WORD(hx, x);
+ if ((hx & 0x7fffffff) == 0x7f800000)
+ return (x + x);
- if (x >= 0.0) {
+ if (!(hx & 0x80000000)) {
t = floorf(x);
- if (t - x <= -0.5)
- t += 1.0;
+ if (t - x <= -0.5F)
+ t += 1;
return (t);
} else {
t = floorf(-x);
- if (t + x <= -0.5)
- t += 1.0;
+ if (t + x <= -0.5F)
+ t += 1;
return (-t);
}
}