Fix wrong ussage of sincos for subnormal arguments
authorLiubov Dmitrieva <liubov.dmitrieva@gmail.com>
Tue, 25 Sep 2012 18:41:17 +0000 (20:41 +0200)
committerAndreas Jaeger <aj@suse.de>
Tue, 25 Sep 2012 18:41:17 +0000 (20:41 +0200)
19 files changed:
ChangeLog
math/s_ccosh.c
math/s_ccoshf.c
math/s_ccoshl.c
math/s_cexp.c
math/s_cexpf.c
math/s_cexpl.c
math/s_csin.c
math/s_csinf.c
math/s_csinh.c
math/s_csinhf.c
math/s_csinhl.c
math/s_csinl.c
math/s_ctan.c
math/s_ctanf.c
math/s_ctanh.c
math/s_ctanhf.c
math/s_ctanhl.c
math/s_ctanl.c

index cea98d1..2a6e038 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2012-09-25  Liubov Dmitrieva  <liubov.dmitrieva@gmail.com>
+
+       * math/s_ccoshf.c (__ccoshf): Fix wrong using of sincosf for
+       subnormal argument.
+       * math/s_cexpf.c (__cexpf): Likewise.
+       * math/s_csinf.c (__csinf): Likewise.
+       * math/s_csinhf.c (__csinhf): Likewise.
+       * math/s_ctanf.c (__ctanf): Likewise.
+       * math/s_ctanhf.c (__ctanhf): Likewise.
+       * math/s_ccosh.c (__ccoshf): Likewise.
+       * math/s_cexp.c (__cexpl): Likewise.
+       * math/s_csin.c (__csin): Likewise.
+       * math/s_csinh.c (__csinh): Likewise.
+       * math/s_ctan.c (__ctan): Likewise.
+       * math/s_ctanh.c (ctanh): Likewise.
+       * math/s_ccoshl.c (__ccoshl): Likewise.
+       * math/s_cexpl.c (__cexpl): Likewise.
+       * math/s_csinl.c (__csinl): Likewise.
+       * math/s_csinhl.c (__csinhl): Likewise.
+       * math/s_ctanl.c (__ctanl): Likewise.
+       * math/s_ctanhl.c (__ctanhl): Likewise.
+
 2012-09-25  Joseph Myers  <joseph@codesourcery.com>
 
        * libio/libio.h (_IO_size_t): Define to size_t, not _G_size_t.
index 44c9944..91477ee 100644 (file)
@@ -39,7 +39,15 @@ __ccosh (__complex__ double x)
          const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2);
          double sinix, cosix;
 
-         __sincos (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincos (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          if (fabs (__real__ x) > t)
            {
@@ -92,7 +100,15 @@ __ccosh (__complex__ double x)
          /* Imaginary part is finite.  */
          double sinix, cosix;
 
-         __sincos (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincos (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          __real__ retval = __copysign (HUGE_VAL, cosix);
          __imag__ retval = (__copysign (HUGE_VAL, sinix)
index d6f8110..9ca57b2 100644 (file)
@@ -39,7 +39,15 @@ __ccoshf (__complex__ float x)
          const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2);
          float sinix, cosix;
 
-         __sincosf (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosf (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0f;
+           }
 
          if (fabsf (__real__ x) > t)
            {
@@ -92,7 +100,15 @@ __ccoshf (__complex__ float x)
          /* Imaginary part is finite.  */
          float sinix, cosix;
 
-         __sincosf (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosf (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0f;
+           }
 
          __real__ retval = __copysignf (HUGE_VALF, cosix);
          __imag__ retval = (__copysignf (HUGE_VALF, sinix)
index 77a9ae3..1d561b4 100644 (file)
@@ -39,7 +39,15 @@ __ccoshl (__complex__ long double x)
          const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l);
          long double sinix, cosix;
 
-         __sincosl (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosl (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          if (fabsl (__real__ x) > t)
            {
@@ -92,7 +100,15 @@ __ccoshl (__complex__ long double x)
          /* Imaginary part is finite.  */
          long double sinix, cosix;
 
-         __sincosl (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosl (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          __real__ retval = __copysignl (HUGE_VALL, cosix);
          __imag__ retval = (__copysignl (HUGE_VALL, sinix)
index 1d7a5a2..d0a95ba 100644 (file)
@@ -39,7 +39,15 @@ __cexp (__complex__ double x)
          const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2);
          double sinix, cosix;
 
-         __sincos (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincos (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          if (__real__ x > t)
            {
@@ -95,7 +103,15 @@ __cexp (__complex__ double x)
            {
              double sinix, cosix;
 
-             __sincos (__imag__ x, &sinix, &cosix);
+             if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+               {
+                 __sincos (__imag__ x, &sinix, &cosix);
+               }
+             else
+               {
+                 sinix = __imag__ x;
+                 cosix = 1.0;
+               }
 
              __real__ retval = __copysign (value, cosix);
              __imag__ retval = __copysign (value, sinix);
index 4aa9765..41fcea5 100644 (file)
@@ -39,7 +39,15 @@ __cexpf (__complex__ float x)
          const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2);
          float sinix, cosix;
 
-         __sincosf (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosf (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0f;
+           }
 
          if (__real__ x > t)
            {
@@ -95,7 +103,15 @@ __cexpf (__complex__ float x)
            {
              float sinix, cosix;
 
-             __sincosf (__imag__ x, &sinix, &cosix);
+             if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+               {
+                 __sincosf (__imag__ x, &sinix, &cosix);
+               }
+             else
+               {
+                 sinix = __imag__ x;
+                 cosix = 1.0f;
+               }
 
              __real__ retval = __copysignf (value, cosix);
              __imag__ retval = __copysignf (value, sinix);
index 2568249..d67cc5e 100644 (file)
@@ -39,7 +39,15 @@ __cexpl (__complex__ long double x)
          const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l);
          long double sinix, cosix;
 
-         __sincosl (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosl (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          if (__real__ x > t)
            {
@@ -95,7 +103,15 @@ __cexpl (__complex__ long double x)
            {
              long double sinix, cosix;
 
-             __sincosl (__imag__ x, &sinix, &cosix);
+             if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+               {
+                 __sincosl (__imag__ x, &sinix, &cosix);
+               }
+             else
+               {
+                 sinix = __imag__ x;
+                 cosix = 1.0;
+               }
 
              __real__ retval = __copysignl (value, cosix);
              __imag__ retval = __copysignl (value, sinix);
index 602c14e..725989c 100644 (file)
@@ -42,7 +42,15 @@ __csin (__complex__ double x)
          const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2);
          double sinix, cosix;
 
-         __sincos (__real__ x, &sinix, &cosix);
+         if (__builtin_expect (rcls != FP_SUBNORMAL, 1))
+           {
+             __sincos (__real__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __real__ x;
+             cosix = 1.0;
+           }
 
          if (fabs (__imag__ x) > t)
            {
@@ -115,7 +123,15 @@ __csin (__complex__ double x)
          /* Real part is finite.  */
          double sinix, cosix;
 
-         __sincos (__real__ x, &sinix, &cosix);
+         if (__builtin_expect (rcls != FP_SUBNORMAL, 1))
+           {
+             __sincos (__real__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __real__ x;
+             cosix = 1.0;
+           }
 
          __real__ retval = __copysign (HUGE_VAL, sinix);
          __imag__ retval = __copysign (HUGE_VAL, cosix);
index c1d6a4f..d53f943 100644 (file)
@@ -42,7 +42,15 @@ __csinf (__complex__ float x)
          const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2);
          float sinix, cosix;
 
-         __sincosf (__real__ x, &sinix, &cosix);
+         if (__builtin_expect (rcls != FP_SUBNORMAL, 1))
+           {
+             __sincosf (__real__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __real__ x;
+             cosix = 1.0f;
+           }
 
          if (fabsf (__imag__ x) > t)
            {
@@ -115,7 +123,15 @@ __csinf (__complex__ float x)
          /* Real part is finite.  */
          float sinix, cosix;
 
-         __sincosf (__real__ x, &sinix, &cosix);
+         if (__builtin_expect (rcls != FP_SUBNORMAL, 1))
+           {
+             __sincosf (__real__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __real__ x;
+             cosix = 1.0f;
+           }
 
          __real__ retval = __copysignf (HUGE_VALF, sinix);
          __imag__ retval = __copysignf (HUGE_VALF, cosix);
index 56bb256..20edbd1 100644 (file)
@@ -42,7 +42,15 @@ __csinh (__complex__ double x)
          const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2);
          double sinix, cosix;
 
-         __sincos (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincos (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          if (fabs (__real__ x) > t)
            {
@@ -109,7 +117,15 @@ __csinh (__complex__ double x)
          /* Imaginary part is finite.  */
          double sinix, cosix;
 
-         __sincos (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincos (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          __real__ retval = __copysign (HUGE_VAL, cosix);
          __imag__ retval = __copysign (HUGE_VAL, sinix);
index ba85e79..4b019a0 100644 (file)
@@ -42,7 +42,15 @@ __csinhf (__complex__ float x)
          const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2);
          float sinix, cosix;
 
-         __sincosf (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosf (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0f;
+           }
 
          if (fabsf (__real__ x) > t)
            {
@@ -109,7 +117,15 @@ __csinhf (__complex__ float x)
          /* Imaginary part is finite.  */
          float sinix, cosix;
 
-         __sincosf (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosf (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0f;
+           }
 
          __real__ retval = __copysignf (HUGE_VALF, cosix);
          __imag__ retval = __copysignf (HUGE_VALF, sinix);
index e482e3a..d9a928a 100644 (file)
@@ -42,7 +42,15 @@ __csinhl (__complex__ long double x)
          const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l);
          long double sinix, cosix;
 
-         __sincosl (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosl (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          if (fabsl (__real__ x) > t)
            {
@@ -109,7 +117,15 @@ __csinhl (__complex__ long double x)
          /* Imaginary part is finite.  */
          long double sinix, cosix;
 
-         __sincosl (__imag__ x, &sinix, &cosix);
+         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+           {
+             __sincosl (__imag__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __imag__ x;
+             cosix = 1.0;
+           }
 
          __real__ retval = __copysignl (HUGE_VALL, cosix);
          __imag__ retval = __copysignl (HUGE_VALL, sinix);
index ff43256..9812bdd 100644 (file)
@@ -42,7 +42,15 @@ __csinl (__complex__ long double x)
          const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l);
          long double sinix, cosix;
 
-         __sincosl (__real__ x, &sinix, &cosix);
+         if (__builtin_expect (rcls != FP_SUBNORMAL, 1))
+           {
+             __sincosl (__real__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __real__ x;
+             cosix = 1.0;
+           }
 
          if (fabsl (__imag__ x) > t)
            {
@@ -115,7 +123,15 @@ __csinl (__complex__ long double x)
          /* Real part is finite.  */
          long double sinix, cosix;
 
-         __sincosl (__real__ x, &sinix, &cosix);
+         if (__builtin_expect (rcls != FP_SUBNORMAL, 1))
+           {
+             __sincosl (__real__ x, &sinix, &cosix);
+           }
+         else
+           {
+             sinix = __real__ x;
+             cosix = 1.0;
+           }
 
          __real__ retval = __copysignl (HUGE_VALL, sinix);
          __imag__ retval = __copysignl (HUGE_VALL, cosix);
index 89c0fef..fdba847 100644 (file)
@@ -53,11 +53,20 @@ __ctan (__complex__ double x)
       double sinrx, cosrx;
       double den;
       const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2 / 2);
+      int rcls = fpclassify (__real__ x);
 
       /* tan(x+iy) = (sin(2x) + i*sinh(2y))/(cos(2x) + cosh(2y))
         = (sin(x)*cos(x) + i*sinh(y)*cosh(y)/(cos(x)^2 + sinh(y)^2). */
 
-      __sincos (__real__ x, &sinrx, &cosrx);
+      if (__builtin_expect (rcls != FP_SUBNORMAL, 1))
+       {
+         __sincos (__real__ x, &sinrx, &cosrx);
+       }
+      else
+       {
+         sinrx = __real__ x;
+         cosrx = 1.0;
+       }
 
       if (fabs (__imag__ x) > t)
        {
index 2559f83..fd2b797 100644 (file)
@@ -57,7 +57,15 @@ __ctanf (__complex__ float x)
       /* tan(x+iy) = (sin(2x) + i*sinh(2y))/(cos(2x) + cosh(2y))
         = (sin(x)*cos(x) + i*sinh(y)*cosh(y)/(cos(x)^2 + sinh(y)^2). */
 
-      __sincosf (__real__ x, &sinrx, &cosrx);
+      if (__builtin_expect (fpclassify(__real__ x) != FP_SUBNORMAL, 1))
+       {
+         __sincosf (__real__ x, &sinrx, &cosrx);
+       }
+      else
+       {
+         sinrx = __real__ x;
+         cosrx = 1.0f;
+       }
 
       if (fabsf (__imag__ x) > t)
        {
index d288b7d..fee1910 100644 (file)
@@ -53,11 +53,20 @@ __ctanh (__complex__ double x)
       double sinix, cosix;
       double den;
       const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2 / 2);
+      int icls = fpclassify (__imag__ x);
 
       /* tanh(x+iy) = (sinh(2x) + i*sin(2y))/(cosh(2x) + cos(2y))
         = (sinh(x)*cosh(x) + i*sin(y)*cos(y))/(sinh(x)^2 + cos(y)^2).  */
 
-      __sincos (__imag__ x, &sinix, &cosix);
+      if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+       {
+         __sincos (__imag__ x, &sinix, &cosix);
+       }
+      else
+       {
+         sinix = __imag__ x;
+         cosix = 1.0;
+       }
 
       if (fabs (__real__ x) > t)
        {
index ca36a83..862845f 100644 (file)
@@ -57,7 +57,15 @@ __ctanhf (__complex__ float x)
       /* tanh(x+iy) = (sinh(2x) + i*sin(2y))/(cosh(2x) + cos(2y))
         = (sinh(x)*cosh(x) + i*sin(y)*cos(y))/(sinh(x)^2 + cos(y)^2).  */
 
-      __sincosf (__imag__ x, &sinix, &cosix);
+      if (__builtin_expect (fpclassify(__imag__ x) != FP_SUBNORMAL, 1))
+       {
+         __sincosf (__imag__ x, &sinix, &cosix);
+       }
+      else
+       {
+         sinix = __imag__ x;
+         cosix = 1.0f;
+       }
 
       if (fabsf (__real__ x) > t)
        {
index dbf1612..c4fc1d3 100644 (file)
@@ -53,11 +53,20 @@ __ctanhl (__complex__ long double x)
       long double sinix, cosix;
       long double den;
       const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2);
+      int icls = fpclassify (__imag__ x);
 
       /* tanh(x+iy) = (sinh(2x) + i*sin(2y))/(cosh(2x) + cos(2y))
         = (sinh(x)*cosh(x) + i*sin(y)*cos(y))/(sinh(x)^2 + cos(y)^2).  */
 
-      __sincosl (__imag__ x, &sinix, &cosix);
+      if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+       {
+         __sincosl (__imag__ x, &sinix, &cosix);
+       }
+      else
+       {
+         sinix = __imag__ x;
+         cosix = 1.0;
+       }
 
       if (fabsl (__real__ x) > t)
        {
index 4fe2611..0affe93 100644 (file)
@@ -53,11 +53,20 @@ __ctanl (__complex__ long double x)
       long double sinrx, cosrx;
       long double den;
       const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2);
+      int rcls = fpclassify (__real__ x);
 
       /* tan(x+iy) = (sin(2x) + i*sinh(2y))/(cos(2x) + cosh(2y))
         = (sin(x)*cos(x) + i*sinh(y)*cosh(y)/(cos(x)^2 + sinh(y)^2). */
 
-      __sincosl (__real__ x, &sinrx, &cosrx);
+      if (__builtin_expect (rcls != FP_SUBNORMAL, 1))
+       {
+         __sincosl (__real__ x, &sinrx, &cosrx);
+       }
+      else
+       {
+         sinrx = __real__ x;
+         cosrx = 1.0;
+       }
 
       if (fabsl (__imag__ x) > t)
        {