OSDN Git Service

Catch up on upstream's round/roundf/roundl.
authorElliott Hughes <enh@google.com>
Fri, 10 Oct 2014 17:21:43 +0000 (10:21 -0700)
committerElliott Hughes <enh@google.com>
Fri, 10 Oct 2014 17:21:43 +0000 (10:21 -0700)
Not sure how we missed these, but better late than never...

Change-Id: Ib08d1bb6e340a1907cbeb1cbe220e33f70642bdc

libm/upstream-freebsd/lib/msun/src/s_round.c
libm/upstream-freebsd/lib/msun/src/s_roundf.c
libm/upstream-freebsd/lib/msun/src/s_roundl.c

index 65de31b..fab3019 100644 (file)
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include <math.h>
+#include <float.h>
+
+#include "math.h"
+#include "math_private.h"
 
 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);
        }
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(round, roundl);
+#endif
index 952e8e7..e7e2eb9 100644 (file)
 #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);
        }
 }
index a70b617..2d15e13 100644 (file)
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include <math.h>
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
 
 long double
 roundl(long double x)
 {
        long double t;
+       uint16_t hx;
+
+       GET_LDBL_EXPSIGN(hx, x);
+       if ((hx & 0x7fff) == 0x7fff)
+               return (x + x);
 
-       if (!isfinite(x))
-               return (x);
+       ENTERI();
 
-       if (x >= 0.0) {
+       if (!(hx & 0x8000)) {
                t = floorl(x);
-               if (t - x <= -0.5)
-                       t += 1.0;
-               return (t);
+               if (t - x <= -0.5L)
+                       t += 1;
+               RETURNI(t);
        } else {
                t = floorl(-x);
-               if (t + x <= -0.5)
-                       t += 1.0;
-               return (-t);
+               if (t + x <= -0.5L)
+                       t += 1;
+               RETURNI(-t);
        }
 }