|
|
12745e |
commit b0abbc21034f0e5edc49023d8fda0616173faf17
|
|
|
12745e |
Author: Alan Modra <amodra@gmail.com>
|
|
|
12745e |
Date: Wed Apr 2 13:46:19 2014 +1030
|
|
|
12745e |
|
|
|
12745e |
Correct IBM long double nextafterl.
|
|
|
12745e |
|
|
|
12745e |
Fix for values near a power of two, and some tidies.
|
|
|
12745e |
|
|
|
12745e |
[BZ #16739]
|
|
|
12745e |
* sysdeps/ieee754/ldbl-128ibm/s_nextafterl.c (__nextafterl): Correct
|
|
|
12745e |
output when value is near a power of two. Use int64_t for lx and
|
|
|
12745e |
remove casts. Use decimal rather than hex exponent constants.
|
|
|
12745e |
Don't use long double multiplication when double will suffice.
|
|
|
12745e |
* math/libm-test.inc (nextafter_test_data): Add tests.
|
|
|
12745e |
* NEWS: Add 16739 and 16786 to bug list.
|
|
|
12745e |
|
|
|
12745e |
diff --git glibc-2.17-c758a686/math/libm-test.inc glibc-2.17-c758a686/math/libm-test.inc
|
|
|
12745e |
index 19194f6..967b679 100644
|
|
|
12745e |
--- glibc-2.17-c758a686/math/libm-test.inc
|
|
|
12745e |
+++ glibc-2.17-c758a686/math/libm-test.inc
|
|
|
12745e |
@@ -8199,6 +8208,14 @@ pow_test (void)
|
|
|
12745e |
#if defined TEST_DOUBLE || defined TEST_LDOUBLE
|
|
|
12745e |
TEST_ff_f (pow, -7.49321e+133, -9.80818e+16, 0, UNDERFLOW_EXCEPTION);
|
|
|
12745e |
#endif
|
|
|
12745e |
+#if defined TEST_LDOUBLE && LDBL_MANT_DIG == 106
|
|
|
12745e |
+ TEST_ff_f (nextafter, 1.0L, -10.0L, 1.0L-0x1p-106L, NO_EXCEPTION),
|
|
|
12745e |
+ TEST_ff_f (nextafter, 1.0L, 10.0L, 1.0L+0x1p-105L, NO_EXCEPTION),
|
|
|
12745e |
+ TEST_ff_f (nextafter, 1.0L-0x1p-106L, 10.0L, 1.0L, NO_EXCEPTION),
|
|
|
12745e |
+ TEST_ff_f (nextafter, -1.0L, -10.0L, -1.0L-0x1p-105L, NO_EXCEPTION),
|
|
|
12745e |
+ TEST_ff_f (nextafter, -1.0L, 10.0L, -1.0L+0x1p-106L, NO_EXCEPTION),
|
|
|
12745e |
+ TEST_ff_f (nextafter, -1.0L+0x1p-106L, -10.0L, -1.0L, NO_EXCEPTION),
|
|
|
12745e |
+#endif
|
|
|
12745e |
|
|
|
12745e |
TEST_ff_f (pow, -1.0, -0xffffff, -1.0);
|
|
|
12745e |
TEST_ff_f (pow, -1.0, -0x1fffffe, 1.0);
|
|
|
12745e |
diff --git glibc-2.17-c758a686/sysdeps/ieee754/ldbl-128ibm/s_nextafterl.c glibc-2.17-c758a686/sysdeps/ieee754/ldbl-128ibm/s_nextafterl.c
|
|
|
12745e |
index 30b1540..bf57cb8 100644
|
|
|
12745e |
--- glibc-2.17-c758a686/sysdeps/ieee754/ldbl-128ibm/s_nextafterl.c
|
|
|
12745e |
+++ glibc-2.17-c758a686/sysdeps/ieee754/ldbl-128ibm/s_nextafterl.c
|
|
|
12745e |
@@ -30,8 +30,7 @@ static char rcsid[] = "$NetBSD: $";
|
|
|
12745e |
|
|
|
12745e |
long double __nextafterl(long double x, long double y)
|
|
|
12745e |
{
|
|
|
12745e |
- int64_t hx,hy,ihx,ihy;
|
|
|
12745e |
- uint64_t lx;
|
|
|
12745e |
+ int64_t hx, hy, ihx, ihy, lx;
|
|
|
12745e |
double xhi, xlo, yhi;
|
|
|
12745e |
|
|
|
12745e |
ldbl_unpack (x, &xhi, &xlo;;
|
|
|
12745e |
@@ -79,19 +78,28 @@ long double __nextafterl(long double x, long double y)
|
|
|
12745e |
u = math_opt_barrier (x);
|
|
|
12745e |
x -= __LDBL_DENORM_MIN__;
|
|
|
12745e |
if (ihx < 0x0360000000000000LL
|
|
|
12745e |
- || (hx > 0 && (int64_t) lx <= 0)
|
|
|
12745e |
- || (hx < 0 && (int64_t) lx > 1)) {
|
|
|
12745e |
+ || (hx > 0 && lx <= 0)
|
|
|
12745e |
+ || (hx < 0 && lx > 1)) {
|
|
|
12745e |
u = u * u;
|
|
|
12745e |
math_force_eval (u); /* raise underflow flag */
|
|
|
12745e |
}
|
|
|
12745e |
return x;
|
|
|
12745e |
}
|
|
|
12745e |
- if (ihx < 0x06a0000000000000LL) { /* ulp will denormal */
|
|
|
12745e |
- INSERT_WORDS64 (yhi, hx & (0x7ffLL<<52));
|
|
|
12745e |
- u = yhi;
|
|
|
12745e |
- u *= 0x1.0000000000000p-105L;
|
|
|
12745e |
+ /* If the high double is an exact power of two and the low
|
|
|
12745e |
+ double is the opposite sign, then 1ulp is one less than
|
|
|
12745e |
+ what we might determine from the high double. Similarly
|
|
|
12745e |
+ if X is an exact power of two, and positive, because
|
|
|
12745e |
+ making it a little smaller will result in the exponent
|
|
|
12745e |
+ decreasing by one and normalisation of the mantissa. */
|
|
|
12745e |
+ if ((hx & 0x000fffffffffffffLL) == 0
|
|
|
12745e |
+ && ((lx != 0 && (hx ^ lx) < 0)
|
|
|
12745e |
+ || (lx == 0 && hx >= 0)))
|
|
|
12745e |
+ ihx -= 1LL << 52;
|
|
|
12745e |
+ if (ihx < (106LL << 52)) { /* ulp will denormal */
|
|
|
12745e |
+ INSERT_WORDS64 (yhi, ihx & (0x7ffLL<<52));
|
|
|
12745e |
+ u = yhi * 0x1p-105;
|
|
|
12745e |
} else {
|
|
|
12745e |
- INSERT_WORDS64 (yhi, (hx & (0x7ffLL<<52))-(0x069LL<<52));
|
|
|
12745e |
+ INSERT_WORDS64 (yhi, (ihx & (0x7ffLL<<52))-(105LL<<52));
|
|
|
12745e |
u = yhi;
|
|
|
12745e |
}
|
|
|
12745e |
return x - u;
|
|
|
12745e |
@@ -109,8 +117,8 @@ long double __nextafterl(long double x, long double y)
|
|
|
12745e |
u = math_opt_barrier (x);
|
|
|
12745e |
x += __LDBL_DENORM_MIN__;
|
|
|
12745e |
if (ihx < 0x0360000000000000LL
|
|
|
12745e |
- || (hx > 0 && (int64_t) lx < 0 && lx != 0x8000000000000001LL)
|
|
|
12745e |
- || (hx < 0 && (int64_t) lx >= 0)) {
|
|
|
12745e |
+ || (hx > 0 && lx < 0 && lx != 0x8000000000000001LL)
|
|
|
12745e |
+ || (hx < 0 && lx >= 0)) {
|
|
|
12745e |
u = u * u;
|
|
|
12745e |
math_force_eval (u); /* raise underflow flag */
|
|
|
12745e |
}
|
|
|
12745e |
@@ -118,12 +126,21 @@ long double __nextafterl(long double x, long double y)
|
|
|
12745e |
x = -0.0L;
|
|
|
12745e |
return x;
|
|
|
12745e |
}
|
|
|
12745e |
- if (ihx < 0x06a0000000000000LL) { /* ulp will denormal */
|
|
|
12745e |
- INSERT_WORDS64 (yhi, hx & (0x7ffLL<<52));
|
|
|
12745e |
- u = yhi;
|
|
|
12745e |
- u *= 0x1.0000000000000p-105L;
|
|
|
12745e |
+ /* If the high double is an exact power of two and the low
|
|
|
12745e |
+ double is the opposite sign, then 1ulp is one less than
|
|
|
12745e |
+ what we might determine from the high double. Similarly
|
|
|
12745e |
+ if X is an exact power of two, and negative, because
|
|
|
12745e |
+ making it a little larger will result in the exponent
|
|
|
12745e |
+ decreasing by one and normalisation of the mantissa. */
|
|
|
12745e |
+ if ((hx & 0x000fffffffffffffLL) == 0
|
|
|
12745e |
+ && ((lx != 0 && (hx ^ lx) < 0)
|
|
|
12745e |
+ || (lx == 0 && hx < 0)))
|
|
|
12745e |
+ ihx -= 1LL << 52;
|
|
|
12745e |
+ if (ihx < (106LL << 52)) { /* ulp will denormal */
|
|
|
12745e |
+ INSERT_WORDS64 (yhi, ihx & (0x7ffLL<<52));
|
|
|
12745e |
+ u = yhi * 0x1p-105;
|
|
|
12745e |
} else {
|
|
|
12745e |
- INSERT_WORDS64 (yhi, (hx & (0x7ffLL<<52))-(0x069LL<<52));
|
|
|
12745e |
+ INSERT_WORDS64 (yhi, (ihx & (0x7ffLL<<52))-(105LL<<52));
|
|
|
12745e |
u = yhi;
|
|
|
12745e |
}
|
|
|
12745e |
return x + u;
|