]> sourceware.org Git - glibc.git/commitdiff
Fix casinh, casin overflow (bug 14996).
authorJoseph Myers <joseph@codesourcery.com>
Mon, 7 Jan 2013 14:59:53 +0000 (14:59 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Mon, 7 Jan 2013 14:59:53 +0000 (14:59 +0000)
ChangeLog
NEWS
math/libm-test.inc
math/s_casinh.c
math/s_casinhf.c
math/s_casinhl.c
sysdeps/i386/fpu/libm-test-ulps
sysdeps/x86_64/fpu/libm-test-ulps

index 9e46e450c0f2839035982f65ff23066936949693..b5be823eefa07487ca4a0eb58a70df4b3ee8d19d 100644 (file)
--- 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 f1105a3205f481539320b5f12cffba32c4527c5f..8a0da94c12c1dfbc47a33b72eadbf329dd1dd8c8 100644 (file)
--- 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.
 
 \f
 Version 2.17
index a586f7ee78011f174d5406aef9a0eb2a0ed99a75..56e321781e3cd2c68066d5451c9afab99a876c65 100644 (file)
@@ -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);
 
index acdf1a1e5acf2d04ba51367eed8410edd7d845f5..b493982d88a34cf3688dbbdb939bb2cb0c4b562f 100644 (file)
@@ -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);
index 8f4315cbf9be81bacd6fd792582cdb2737041554..f865e1449079624af8349f6beaab3bc8ac442e33 100644 (file)
@@ -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);
index 83f8d1885df80cd192bd03aeaafa54642aab0338..d7c74593e4c5e9fd9c562871ee0667dc94c93832 100644 (file)
 #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);
index 3ad23d73ceee7e5218208cc56444f13bcb6e69b5..3fc30de462f27d52b89c711967371500eae1e243 100644 (file)
@@ -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
index 457869307ef4175dc3ad03137db9114b27cc8742..95b6aec81e0b4db8021647dd31a3eeaefb88fe2f 100644 (file)
@@ -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
This page took 0.167193 seconds and 5 git commands to generate.