|
|
ce426f |
# commit da13146da10360436941e843834c90a9aef5fd7a
|
|
|
ce426f |
# Author: Alan Modra <amodra@gmail.com>
|
|
|
ce426f |
# Date: Sat Aug 17 18:30:23 2013 +0930
|
|
|
ce426f |
#
|
|
|
ce426f |
# PowerPC floating point little-endian [10 of 15]
|
|
|
ce426f |
# http://sourceware.org/ml/libc-alpha/2013-07/msg00201.html
|
|
|
ce426f |
#
|
|
|
ce426f |
# These two functions oddly test x+1>0 when a double x is >= 0.0, and
|
|
|
ce426f |
# similarly when x is negative. I don't see the point of that since the
|
|
|
ce426f |
# test should always be true. I also don't see any need to convert x+1
|
|
|
ce426f |
# to integer rather than simply using xr+1. Note that the standard
|
|
|
ce426f |
# allows these functions to return any value when the input is outside
|
|
|
ce426f |
# the range of long long, but it's not too hard to prevent xr+1
|
|
|
ce426f |
# overflowing so that's what I've done.
|
|
|
ce426f |
#
|
|
|
ce426f |
# (With rounding mode FE_UPWARD, x+1 can be a lot more than what you
|
|
|
ce426f |
# might naively expect, but perhaps that situation was covered by the
|
|
|
ce426f |
# x - xrf < 1.0 test.)
|
|
|
ce426f |
#
|
|
|
ce426f |
# * sysdeps/powerpc/fpu/s_llround.c (__llround): Rewrite.
|
|
|
ce426f |
# * sysdeps/powerpc/fpu/s_llroundf.c (__llroundf): Rewrite.
|
|
|
ce426f |
#
|
|
|
ce426f |
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/s_llround.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/s_llround.c
|
|
|
ce426f |
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/s_llround.c 2014-05-27 22:38:55.000000000 -0500
|
|
|
ce426f |
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/s_llround.c 2014-05-27 22:38:58.000000000 -0500
|
|
|
ce426f |
@@ -19,29 +19,28 @@
|
|
|
ce426f |
#include <math.h>
|
|
|
ce426f |
#include <math_ldbl_opt.h>
|
|
|
ce426f |
|
|
|
ce426f |
-/* I think that what this routine is supposed to do is round a value
|
|
|
ce426f |
- to the nearest integer, with values exactly on the boundary rounded
|
|
|
ce426f |
- away from zero. */
|
|
|
ce426f |
-/* This routine relies on (long long)x, when x is out of range of a long long,
|
|
|
ce426f |
- clipping to MAX_LLONG or MIN_LLONG. */
|
|
|
ce426f |
+/* Round to the nearest integer, with values exactly on a 0.5 boundary
|
|
|
ce426f |
+ rounded away from zero, regardless of the current rounding mode.
|
|
|
ce426f |
+ If (long long)x, when x is out of range of a long long, clips at
|
|
|
ce426f |
+ LLONG_MAX or LLONG_MIN, then this implementation also clips. */
|
|
|
ce426f |
|
|
|
ce426f |
long long int
|
|
|
ce426f |
__llround (double x)
|
|
|
ce426f |
{
|
|
|
ce426f |
- double xrf;
|
|
|
ce426f |
- long long int xr;
|
|
|
ce426f |
- xr = (long long int) x;
|
|
|
ce426f |
- xrf = (double) xr;
|
|
|
ce426f |
+ long long xr = (long long) x;
|
|
|
ce426f |
+ double xrf = (double) xr;
|
|
|
ce426f |
+
|
|
|
ce426f |
if (x >= 0.0)
|
|
|
ce426f |
- if (x - xrf >= 0.5 && x - xrf < 1.0 && x+1 > 0)
|
|
|
ce426f |
- return x+1;
|
|
|
ce426f |
- else
|
|
|
ce426f |
- return x;
|
|
|
ce426f |
+ {
|
|
|
ce426f |
+ if (x - xrf >= 0.5)
|
|
|
ce426f |
+ xr += (long long) ((unsigned long long) xr + 1) > 0;
|
|
|
ce426f |
+ }
|
|
|
ce426f |
else
|
|
|
ce426f |
- if (xrf - x >= 0.5 && xrf - x < 1.0 && x-1 < 0)
|
|
|
ce426f |
- return x-1;
|
|
|
ce426f |
- else
|
|
|
ce426f |
- return x;
|
|
|
ce426f |
+ {
|
|
|
ce426f |
+ if (xrf - x >= 0.5)
|
|
|
ce426f |
+ xr -= (long long) ((unsigned long long) xr - 1) < 0;
|
|
|
ce426f |
+ }
|
|
|
ce426f |
+ return xr;
|
|
|
ce426f |
}
|
|
|
ce426f |
weak_alias (__llround, llround)
|
|
|
ce426f |
#ifdef NO_LONG_DOUBLE
|
|
|
ce426f |
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/s_llroundf.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/s_llroundf.c
|
|
|
ce426f |
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/s_llroundf.c 2014-05-27 22:38:55.000000000 -0500
|
|
|
ce426f |
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/s_llroundf.c 2014-05-27 22:38:58.000000000 -0500
|
|
|
ce426f |
@@ -18,28 +18,27 @@
|
|
|
ce426f |
|
|
|
ce426f |
#include <math.h>
|
|
|
ce426f |
|
|
|
ce426f |
-/* I think that what this routine is supposed to do is round a value
|
|
|
ce426f |
- to the nearest integer, with values exactly on the boundary rounded
|
|
|
ce426f |
- away from zero. */
|
|
|
ce426f |
-/* This routine relies on (long long)x, when x is out of range of a long long,
|
|
|
ce426f |
- clipping to MAX_LLONG or MIN_LLONG. */
|
|
|
ce426f |
+/* Round to the nearest integer, with values exactly on a 0.5 boundary
|
|
|
ce426f |
+ rounded away from zero, regardless of the current rounding mode.
|
|
|
ce426f |
+ If (long long)x, when x is out of range of a long long, clips at
|
|
|
ce426f |
+ LLONG_MAX or LLONG_MIN, then this implementation also clips. */
|
|
|
ce426f |
|
|
|
ce426f |
long long int
|
|
|
ce426f |
__llroundf (float x)
|
|
|
ce426f |
{
|
|
|
ce426f |
- float xrf;
|
|
|
ce426f |
- long long int xr;
|
|
|
ce426f |
- xr = (long long int) x;
|
|
|
ce426f |
- xrf = (float) xr;
|
|
|
ce426f |
+ long long xr = (long long) x;
|
|
|
ce426f |
+ float xrf = (float) xr;
|
|
|
ce426f |
+
|
|
|
ce426f |
if (x >= 0.0)
|
|
|
ce426f |
- if (x - xrf >= 0.5 && x - xrf < 1.0 && x+1 > 0)
|
|
|
ce426f |
- return x+1;
|
|
|
ce426f |
- else
|
|
|
ce426f |
- return x;
|
|
|
ce426f |
+ {
|
|
|
ce426f |
+ if (x - xrf >= 0.5)
|
|
|
ce426f |
+ xr += (long long) ((unsigned long long) xr + 1) > 0;
|
|
|
ce426f |
+ }
|
|
|
ce426f |
else
|
|
|
ce426f |
- if (xrf - x >= 0.5 && xrf - x < 1.0 && x-1 < 0)
|
|
|
ce426f |
- return x-1;
|
|
|
ce426f |
- else
|
|
|
ce426f |
- return x;
|
|
|
ce426f |
+ {
|
|
|
ce426f |
+ if (xrf - x >= 0.5)
|
|
|
ce426f |
+ xr -= (long long) ((unsigned long long) xr - 1) < 0;
|
|
|
ce426f |
+ }
|
|
|
ce426f |
+ return xr;
|
|
|
ce426f |
}
|
|
|
ce426f |
weak_alias (__llroundf, llroundf)
|