aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/ieee754/ldbl-128ibm/e_jnl.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2014-06-27 14:52:13 +0000
committerJoseph Myers <joseph@codesourcery.com>2014-06-27 14:52:13 +0000
commitbe25493251c014a696b62834b0e63b155d8fe353 (patch)
tree2a7ed0745694dfd02fb848ddc702a262acd31fe1 /sysdeps/ieee754/ldbl-128ibm/e_jnl.c
parentb351d85aa284f81271bc93e11301e1c2466b7c82 (diff)
downloadglibc-be25493251c014a696b62834b0e63b155d8fe353.zip
glibc-be25493251c014a696b62834b0e63b155d8fe353.tar.gz
glibc-be25493251c014a696b62834b0e63b155d8fe353.tar.bz2
Fix yn overflow handling in non-default rounding modes (bug 16561, bug 16562).
This patch fixes bugs 16561 and 16562, bad results of yn in overflow cases in non-default rounding modes, both because an intermediate overflow in the recurrence does not get detected if the result is not an infinity and because an overflowing result may occur in the wrong sign. The fix is to set FE_TONEAREST mode internally for the parts of the function where such overflows can occur (which includes the call to y1 - where yn is used to compute a Bessel function of order -1, negating the result of y1 isn't correct for overflowing results in directed rounding modes) and then compute an overflowing value in the original rounding mode if the to-nearest result was an infinity. Tested x86_64 and x86 and ulps updated accordingly. Also tested for mips64 and powerpc32 to test the ldbl-128 and ldbl-128ibm changes. (The tests for these bugs were added in my previous y1 patch, so the only thing this patch has to do with the testsuite is enable yn testing in all rounding modes.) [BZ #16561] [BZ #16562] * sysdeps/ieee754/dbl-64/e_jn.c: Include <float.h>. (__ieee754_yn): Set FE_TONEAREST mode internally and then recompute overflowing results in original rounding mode. * sysdeps/ieee754/flt-32/e_jnf.c: Include <float.h>. (__ieee754_ynf): Set FE_TONEAREST mode internally and then recompute overflowing results in original rounding mode. * sysdeps/ieee754/ldbl-128/e_jnl.c: Include <float.h>. (__ieee754_ynl): Set FE_TONEAREST mode internally and then recompute overflowing results in original rounding mode. * sysdeps/ieee754/ldbl-128ibm/e_jnl.c: Include <float.h>. (__ieee754_ynl): Set FE_TONEAREST mode internally and then recompute overflowing results in original rounding mode. * sysdeps/ieee754/ldbl-96/e_jnl.c: Include <float.h>. (__ieee754_ynl): Set FE_TONEAREST mode internally and then recompute overflowing results in original rounding mode. * sysdeps/i386/fpu/fenv_private.h [!__SSE2_MATH__] (libc_feholdsetround_ctx): New macro. * math/libm-test.inc (yn_test): Use ALL_RM_TEST. * sysdeps/i386/fpu/libm-test-ulps: Update. * sysdeps/x86_64/fpu/libm-test-ulps : Likewise.
Diffstat (limited to 'sysdeps/ieee754/ldbl-128ibm/e_jnl.c')
-rw-r--r--sysdeps/ieee754/ldbl-128ibm/e_jnl.c143
1 files changed, 77 insertions, 66 deletions
diff --git a/sysdeps/ieee754/ldbl-128ibm/e_jnl.c b/sysdeps/ieee754/ldbl-128ibm/e_jnl.c
index 6761a0d..589f1f8 100644
--- a/sysdeps/ieee754/ldbl-128ibm/e_jnl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/e_jnl.c
@@ -57,6 +57,7 @@
*/
#include <errno.h>
+#include <float.h>
#include <math.h>
#include <math_private.h>
@@ -300,7 +301,7 @@ __ieee754_ynl (int n, long double x)
uint32_t se, lx;
int32_t i, ix;
int32_t sign;
- long double a, b, temp;
+ long double a, b, temp, ret;
double xhi;
xhi = ldbl_high (x);
@@ -328,72 +329,82 @@ __ieee754_ynl (int n, long double x)
}
if (n == 0)
return (__ieee754_y0l (x));
- if (n == 1)
- return (sign * __ieee754_y1l (x));
- if (ix >= 0x7ff00000)
- return zero;
- if (ix >= 0x52D00000)
- { /* x > 2**302 */
+ {
+ SET_RESTORE_ROUNDL (FE_TONEAREST);
+ if (n == 1)
+ {
+ ret = sign * __ieee754_y1l (x);
+ goto out;
+ }
+ if (ix >= 0x7ff00000)
+ return zero;
+ if (ix >= 0x52D00000)
+ { /* x > 2**302 */
- /* ??? See comment above on the possible futility of this. */
+ /* ??? See comment above on the possible futility of this. */
- /* (x >> n**2)
- * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
- * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
- * Let s=sin(x), c=cos(x),
- * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
- *
- * n sin(xn)*sqt2 cos(xn)*sqt2
- * ----------------------------------
- * 0 s-c c+s
- * 1 -s-c -c+s
- * 2 -s+c -c-s
- * 3 s+c c-s
- */
- long double s;
- long double c;
- __sincosl (x, &s, &c);
- switch (n & 3)
- {
- case 0:
- temp = s - c;
- break;
- case 1:
- temp = -s - c;
- break;
- case 2:
- temp = -s + c;
- break;
- case 3:
- temp = s + c;
- break;
- }
- b = invsqrtpi * temp / __ieee754_sqrtl (x);
- }
- else
- {
- a = __ieee754_y0l (x);
- b = __ieee754_y1l (x);
- /* quit if b is -inf */
- xhi = ldbl_high (b);
- GET_HIGH_WORD (se, xhi);
- se &= 0xfff00000;
- for (i = 1; i < n && se != 0xfff00000; i++)
- {
- temp = b;
- b = ((long double) (i + i) / x) * b - a;
- xhi = ldbl_high (b);
- GET_HIGH_WORD (se, xhi);
- se &= 0xfff00000;
- a = temp;
- }
- }
- /* If B is +-Inf, set up errno accordingly. */
- if (! __finitel (b))
- __set_errno (ERANGE);
- if (sign > 0)
- return b;
- else
- return -b;
+ /* (x >> n**2)
+ * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
+ * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
+ * Let s=sin(x), c=cos(x),
+ * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
+ *
+ * n sin(xn)*sqt2 cos(xn)*sqt2
+ * ----------------------------------
+ * 0 s-c c+s
+ * 1 -s-c -c+s
+ * 2 -s+c -c-s
+ * 3 s+c c-s
+ */
+ long double s;
+ long double c;
+ __sincosl (x, &s, &c);
+ switch (n & 3)
+ {
+ case 0:
+ temp = s - c;
+ break;
+ case 1:
+ temp = -s - c;
+ break;
+ case 2:
+ temp = -s + c;
+ break;
+ case 3:
+ temp = s + c;
+ break;
+ }
+ b = invsqrtpi * temp / __ieee754_sqrtl (x);
+ }
+ else
+ {
+ a = __ieee754_y0l (x);
+ b = __ieee754_y1l (x);
+ /* quit if b is -inf */
+ xhi = ldbl_high (b);
+ GET_HIGH_WORD (se, xhi);
+ se &= 0xfff00000;
+ for (i = 1; i < n && se != 0xfff00000; i++)
+ {
+ temp = b;
+ b = ((long double) (i + i) / x) * b - a;
+ xhi = ldbl_high (b);
+ GET_HIGH_WORD (se, xhi);
+ se &= 0xfff00000;
+ a = temp;
+ }
+ }
+ /* If B is +-Inf, set up errno accordingly. */
+ if (! __finitel (b))
+ __set_errno (ERANGE);
+ if (sign > 0)
+ ret = b;
+ else
+ ret = -b;
+ }
+ out:
+ if (__isinfl (ret))
+ ret = __copysignl (LDBL_MAX, ret) * LDBL_MAX;
+ return ret;
}
strong_alias (__ieee754_ynl, __ynl_finite)