diff options
author | Joseph Myers <joseph@codesourcery.com> | 2013-01-07 14:59:53 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2013-01-07 14:59:53 +0000 |
commit | a9708fed779ff4e61e07ec2eae78e5c0753e1222 (patch) | |
tree | b673bfb73f85b6d680f518cb062ef9dc7828642c | |
parent | afec409af996af8efb082c109d0dd9fc211f4d8e (diff) | |
download | glibc-a9708fed779ff4e61e07ec2eae78e5c0753e1222.tar.gz glibc-a9708fed779ff4e61e07ec2eae78e5c0753e1222.tar.xz glibc-a9708fed779ff4e61e07ec2eae78e5c0753e1222.zip |
Fix casinh, casin overflow (bug 14996).
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | math/libm-test.inc | 16 | ||||
-rw-r--r-- | math/s_casinh.c | 28 | ||||
-rw-r--r-- | math/s_casinhf.c | 28 | ||||
-rw-r--r-- | math/s_casinhl.c | 33 | ||||
-rw-r--r-- | sysdeps/i386/fpu/libm-test-ulps | 12 | ||||
-rw-r--r-- | sysdeps/x86_64/fpu/libm-test-ulps | 12 |
8 files changed, 128 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog index 9e46e450c0..b5be823eef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2013-01-07 Joseph Myers <joseph@codesourcery.com> + + [BZ #14996] + * math/s_casinh.c: Include <float.h>. + (__casinh): Do not do computation with squaring and square root + for large arguments. + * math/s_casinhf.c: Include <float.h>. + (__casinhf): Do not do computation with squaring and square root + for large arguments. + * math/s_casinhl.c: Include <float.h>. + [LDBL_MANT_DIG == 106] (LDBL_EPSILON): Undefine and redefine. + (__casinhl): Do not do computation with squaring and square root + for large arguments. + * math/libm-test.inc (casin_test): Add more tests. + (casinh_test): Likewise. + * sysdeps/i386/fpu/libm-test-ulps: Update. + * sysdeps/x86_64/fpu/libm-test-ulps: Likewise. + 2013-01-04 H.J. Lu <hongjiu.lu@intel.com> * sysdeps/i386/i686/cacheinfo.c (__x86_64_data_cache_size): Removed. diff --git a/NEWS b/NEWS index f1105a3205..8a0da94c12 100644 --- a/NEWS +++ b/NEWS @@ -9,7 +9,7 @@ Version 2.18 * The following bugs are resolved with this release: - 13951, 14317, 14981, 14982, 14994. + 13951, 14317, 14981, 14982, 14994, 14996. Version 2.17 diff --git a/math/libm-test.inc b/math/libm-test.inc index a586f7ee78..56e321781e 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -1727,6 +1727,14 @@ casin_test (void) TEST_c_c (casin, -1.0L, -0x1p5000L, -7.079811261048172892385615158694057552948e-1506L, -3.466429049980286492395577839412341016946e3L); #endif + TEST_c_c (casin, 0x1.fp127L, 0x1.fp127L, 7.853981633974483096156608458198757210493e-1L, 8.973081118419833726837456344608533993585e1L); +#ifndef TEST_FLOAT + TEST_c_c (casin, 0x1.fp1023L, 0x1.fp1023L, 7.853981633974483096156608458198757210493e-1L, 7.107906849659093345062145442726115449315e2L); +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (casin, 0x1.fp16383L, 0x1.fp16383L, 7.853981633974483096156608458198757210493e-1L, 1.135753137836666928715489992987020363057e4L); +#endif + TEST_c_c (casin, 0.75L, 1.25L, 0.453276177638793913448921196101971749L, 1.13239363160530819522266333696834467L); TEST_c_c (casin, -2, -3, -0.57065278432109940071028387968566963L, -1.9833870299165354323470769028940395L); @@ -1846,6 +1854,14 @@ casinh_test (void) TEST_c_c (casinh, -1.0L, -0x1p5000L, -3.466429049980286492395577839412341016946e3L, -1.570796326794896619231321691639751442099L); #endif + TEST_c_c (casinh, 0x1.fp127L, 0x1.fp127L, 8.973081118419833726837456344608533993585e1L, 7.853981633974483096156608458198757210493e-1L); +#ifndef TEST_FLOAT + TEST_c_c (casinh, 0x1.fp1023L, 0x1.fp1023L, 7.107906849659093345062145442726115449315e2L, 7.853981633974483096156608458198757210493e-1L); +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (casinh, 0x1.fp16383L, 0x1.fp16383L, 1.135753137836666928715489992987020363057e4L, 7.853981633974483096156608458198757210493e-1L); +#endif + TEST_c_c (casinh, 0.75L, 1.25L, 1.03171853444778027336364058631006594L, 0.911738290968487636358489564316731207L); TEST_c_c (casinh, -2, -3, -1.9686379257930962917886650952454982L, -0.96465850440760279204541105949953237L); diff --git a/math/s_casinh.c b/math/s_casinh.c index acdf1a1e5a..b493982d88 100644 --- a/math/s_casinh.c +++ b/math/s_casinh.c @@ -20,7 +20,7 @@ #include <complex.h> #include <math.h> #include <math_private.h> - +#include <float.h> __complex__ double __casinh (__complex__ double x) @@ -69,15 +69,29 @@ __casinh (__complex__ double x) rx = fabs (__real__ x); ix = fabs (__imag__ x); - __real__ y = (rx - ix) * (rx + ix) + 1.0; - __imag__ y = 2.0 * rx * ix; + if (rx >= 1.0 / DBL_EPSILON || ix >= 1.0 / DBL_EPSILON) + { + /* For large x in the first quadrant, x + csqrt (1 + x * x) + is sufficiently close to 2 * x to make no significant + difference to the result; avoid possible overflow from + the squaring and addition. */ + __real__ y = rx; + __imag__ y = ix; + res = __clog (y); + __real__ res += M_LN2; + } + else + { + __real__ y = (rx - ix) * (rx + ix) + 1.0; + __imag__ y = 2.0 * rx * ix; - y = __csqrt (y); + y = __csqrt (y); - __real__ y += rx; - __imag__ y += ix; + __real__ y += rx; + __imag__ y += ix; - res = __clog (y); + res = __clog (y); + } /* Give results the correct sign for the original argument. */ __real__ res = __copysign (__real__ res, __real__ x); diff --git a/math/s_casinhf.c b/math/s_casinhf.c index 8f4315cbf9..f865e14490 100644 --- a/math/s_casinhf.c +++ b/math/s_casinhf.c @@ -20,7 +20,7 @@ #include <complex.h> #include <math.h> #include <math_private.h> - +#include <float.h> __complex__ float __casinhf (__complex__ float x) @@ -69,15 +69,29 @@ __casinhf (__complex__ float x) rx = fabsf (__real__ x); ix = fabsf (__imag__ x); - __real__ y = (rx - ix) * (rx + ix) + 1.0; - __imag__ y = 2.0 * rx * ix; + if (rx >= 1.0f / FLT_EPSILON || ix >= 1.0f / FLT_EPSILON) + { + /* For large x in the first quadrant, x + csqrt (1 + x * x) + is sufficiently close to 2 * x to make no significant + difference to the result; avoid possible overflow from + the squaring and addition. */ + __real__ y = rx; + __imag__ y = ix; + res = __clogf (y); + __real__ res += (float) M_LN2; + } + else + { + __real__ y = (rx - ix) * (rx + ix) + 1.0; + __imag__ y = 2.0 * rx * ix; - y = __csqrtf (y); + y = __csqrtf (y); - __real__ y += rx; - __imag__ y += ix; + __real__ y += rx; + __imag__ y += ix; - res = __clogf (y); + res = __clogf (y); + } /* Give results the correct sign for the original argument. */ __real__ res = __copysignf (__real__ res, __real__ x); diff --git a/math/s_casinhl.c b/math/s_casinhl.c index 83f8d1885d..d7c74593e4 100644 --- a/math/s_casinhl.c +++ b/math/s_casinhl.c @@ -20,7 +20,14 @@ #include <complex.h> #include <math.h> #include <math_private.h> +#include <float.h> +/* To avoid spurious overflows, use this definition to treat IBM long + double as approximating an IEEE-style format. */ +#if LDBL_MANT_DIG == 106 +# undef LDBL_EPSILON +# define LDBL_EPSILON 0x1p-106L +#endif __complex__ long double __casinhl (__complex__ long double x) @@ -69,15 +76,29 @@ __casinhl (__complex__ long double x) rx = fabsl (__real__ x); ix = fabsl (__imag__ x); - __real__ y = (rx - ix) * (rx + ix) + 1.0; - __imag__ y = 2.0 * rx * ix; + if (rx >= 1.0L / LDBL_EPSILON || ix >= 1.0L / LDBL_EPSILON) + { + /* For large x in the first quadrant, x + csqrt (1 + x * x) + is sufficiently close to 2 * x to make no significant + difference to the result; avoid possible overflow from + the squaring and addition. */ + __real__ y = rx; + __imag__ y = ix; + res = __clogl (y); + __real__ res += M_LN2l; + } + else + { + __real__ y = (rx - ix) * (rx + ix) + 1.0; + __imag__ y = 2.0 * rx * ix; - y = __csqrtl (y); + y = __csqrtl (y); - __real__ y += rx; - __imag__ y += ix; + __real__ y += rx; + __imag__ y += ix; - res = __clogl (y); + res = __clogl (y); + } /* Give results the correct sign for the original argument. */ __real__ res = __copysignl (__real__ res, __real__ x); diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index 3ad23d73ce..3fc30de462 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -518,6 +518,12 @@ float: 1 ifloat: 1 ildouble: 2 ldouble: 2 +Test "Imaginary part of: casin (0x1.fp1023 + 0x1.fp1023 i) == 7.853981633974483096156608458198757210493e-1 + 7.107906849659093345062145442726115449315e2 i": +double: 1 +idouble: 1 +Test "Imaginary part of: casin (0x1.fp127 + 0x1.fp127 i) == 7.853981633974483096156608458198757210493e-1 + 8.973081118419833726837456344608533993585e1 i": +double: 1 +idouble: 1 Test "Imaginary part of: casin (1.5 + +0 i) == pi/2 + 0.9624236501192068949955178268487368462704 i": double: 1 float: 1 @@ -626,6 +632,12 @@ idouble: 1 ifloat: 1 ildouble: 1 ldouble: 1 +Test "Real part of: casinh (0x1.fp1023 + 0x1.fp1023 i) == 7.107906849659093345062145442726115449315e2 + 7.853981633974483096156608458198757210493e-1 i": +double: 1 +idouble: 1 +Test "Real part of: casinh (0x1.fp127 + 0x1.fp127 i) == 8.973081118419833726837456344608533993585e1 + 7.853981633974483096156608458198757210493e-1 i": +double: 1 +idouble: 1 Test "Real part of: casinh (1.0 + +0 i) == 0.8813735870195430252326093249797923090282 + +0 i": double: 1 float: 1 diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index 457869307e..95b6aec81e 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -467,6 +467,12 @@ float: 1 ifloat: 1 ildouble: 2 ldouble: 2 +Test "Imaginary part of: casin (0x1.fp1023 + 0x1.fp1023 i) == 7.853981633974483096156608458198757210493e-1 + 7.107906849659093345062145442726115449315e2 i": +double: 1 +idouble: 1 +Test "Imaginary part of: casin (0x1.fp127 + 0x1.fp127 i) == 7.853981633974483096156608458198757210493e-1 + 8.973081118419833726837456344608533993585e1 i": +double: 1 +idouble: 1 Test "Imaginary part of: casin (1.5 + +0 i) == pi/2 + 0.9624236501192068949955178268487368462704 i": double: 1 float: 1 @@ -571,6 +577,12 @@ idouble: 1 ifloat: 1 ildouble: 1 ldouble: 1 +Test "Real part of: casinh (0x1.fp1023 + 0x1.fp1023 i) == 7.107906849659093345062145442726115449315e2 + 7.853981633974483096156608458198757210493e-1 i": +double: 1 +idouble: 1 +Test "Real part of: casinh (0x1.fp127 + 0x1.fp127 i) == 8.973081118419833726837456344608533993585e1 + 7.853981633974483096156608458198757210493e-1 i": +double: 1 +idouble: 1 Test "Real part of: casinh (1.0 + +0 i) == 0.8813735870195430252326093249797923090282 + +0 i": double: 1 float: 1 |