about summary refs log tree commit diff
path: root/sysdeps/ieee754/ldbl-128ibm
diff options
context:
space:
mode:
authorAdhemerval Zanella <azanella@linux.vnet.ibm.com>2012-07-11 09:19:27 -0300
committerAdhemerval Zanella <azanella@linux.vnet.ibm.com>2012-07-11 09:19:27 -0300
commit28cfe84316f92dbb3e48831d6f7eb4511e3ddf60 (patch)
treed369fe4d47350503213cee5325b89dbcd8272ac3 /sysdeps/ieee754/ldbl-128ibm
parent6b90f98178023e015ca0f1232dd42362d7f49600 (diff)
downloadglibc-28cfe84316f92dbb3e48831d6f7eb4511e3ddf60.tar.gz
glibc-28cfe84316f92dbb3e48831d6f7eb4511e3ddf60.tar.xz
glibc-28cfe84316f92dbb3e48831d6f7eb4511e3ddf60.zip
Fix ctan, ctanh of subnormals in round-upwards mode (bug 14328).
IBM long double fixes and POWER ulps update.
Diffstat (limited to 'sysdeps/ieee754/ldbl-128ibm')
-rw-r--r--sysdeps/ieee754/ldbl-128ibm/s_ctanhl.c38
-rw-r--r--sysdeps/ieee754/ldbl-128ibm/s_ctanl.c34
2 files changed, 50 insertions, 22 deletions
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_ctanhl.c b/sysdeps/ieee754/ldbl-128ibm/s_ctanhl.c
index 2ab80a2246..e11ce56781 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_ctanhl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_ctanhl.c
@@ -25,6 +25,8 @@
 
 #include <math_private.h>
 
+/* IBM long double GCC builtin sets LDBL_EPSILON == LDBL_DENORM_MIN  */
+static const long double ldbl_eps =  0x1p-106L;
 
 __complex__ long double
 __ctanhl (__complex__ long double x)
@@ -35,8 +37,8 @@ __ctanhl (__complex__ long double x)
     {
       if (__isinfl (__real__ x))
 	{
-	  __real__ res = __copysignl (1.0, __real__ x);
-	  __imag__ res = __copysignl (0.0, __imag__ x);
+	  __real__ res = __copysignl (1.0L, __real__ x);
+	  __imag__ res = __copysignl (0.0L, __imag__ x);
 	}
       else if (__imag__ x == 0.0)
 	{
@@ -57,7 +59,7 @@ __ctanhl (__complex__ long double x)
     {
       long double sinix, cosix;
       long double den;
-      const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2);
+      const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2.0L);
 
       /* 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).  */
@@ -71,7 +73,7 @@ __ctanhl (__complex__ long double x)
 	     the real part is +/- 1, the imaginary part is
 	     sin(y)*cos(y)/sinh(x)^2 = 4*sin(y)*cos(y)/exp(2x).  */
 	  long double exp_2t = __ieee754_expl (2 * t);
-	  __real__ res = __copysignl (1.0, __real__ x);
+	  __real__ res = __copysignl (1.0L, __real__ x);
 	  __imag__ res = 4 * sinix * cosix;
 	  __real__ x = fabsl (__real__ x);
 	  __real__ x -= t;
@@ -83,22 +85,34 @@ __ctanhl (__complex__ long double x)
 	      __imag__ res /= exp_2t;
 	    }
 	  else
-	    __imag__ res /= __ieee754_expl (2 * __real__ x);
+	    __imag__ res /= __ieee754_expl (2.0L * __real__ x);
 	}
       else
 	{
-	  long double sinhrx = __ieee754_sinhl (__real__ x);
-	  long double coshrx = __ieee754_coshl (__real__ x);
+	  long double sinhrx, coshrx;
+	  if (fabs (__real__ x) > LDBL_MIN)
+	    {
+	      sinhrx = __ieee754_sinhl (__real__ x);
+	      coshrx = __ieee754_coshl (__real__ x);
+	    }
+	  else
+	    {
+	      sinhrx = __real__ x;
+	      coshrx = 1.0L;
+	    }
 
-	  den = sinhrx * sinhrx + cosix * cosix;
-	  __real__ res = sinhrx * coshrx / den;
-	  __imag__ res = sinix * cosix / den;
+	  if (fabsl (sinhrx) > fabsl (cosix) * ldbl_eps)
+	    den = sinhrx * sinhrx + cosix * cosix;
+	  else
+	    den = cosix * cosix;
+	  __real__ res = sinhrx * (coshrx / den);
+	  __imag__ res = sinix * (cosix / den);
 	}
       /* __gcc_qmul does not respect -0.0 so we need the following fixup.  */
-      if ((__real__ res == 0.0) && (__real__ x == 0.0))
+      if ((__real__ res == 0.0L) && (__real__ x == 0.0L))
         __real__ res = __real__ x;
 
-      if ((__real__ res == 0.0) && (__imag__ x == 0.0))
+      if ((__real__ res == 0.0L) && (__imag__ x == 0.0L))
         __imag__ res = __imag__ x;
     }
 
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_ctanl.c b/sysdeps/ieee754/ldbl-128ibm/s_ctanl.c
index 9d89bbe311..34a370a308 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_ctanl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_ctanl.c
@@ -25,6 +25,8 @@
 
 #include <math_private.h>
 
+/* IBM long double GCC builtin sets LDBL_EPSILON == LDBL_DENORM_MIN  */
+static const long double ldbl_eps = 0x1p-106L;
 
 __complex__ long double
 __ctanl (__complex__ long double x)
@@ -55,7 +57,7 @@ __ctanl (__complex__ long double x)
     {
       long double sinrx, cosrx;
       long double den;
-      const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2);
+      const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2.0L);
 
       /* 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). */
@@ -70,7 +72,7 @@ __ctanl (__complex__ long double x)
 	    sin(x)*cos(x)/sinh(y)^2 = 4*sin(x)*cos(x)/exp(2y).  */
 	  long double exp_2t = __ieee754_expl (2 * t);
 
-	  __imag__ res = __copysignl (1.0, __imag__ x);
+	  __imag__ res = __copysignl (1.0L, __imag__ x);
 	  __real__ res = 4 * sinrx * cosrx;
 	  __imag__ x = fabsl (__imag__ x);
 	  __imag__ x -= t;
@@ -82,23 +84,35 @@ __ctanl (__complex__ long double x)
 	      __real__ res /= exp_2t;
 	    }
 	  else
-	    __real__ res /= __ieee754_expl (2 * __imag__ x);
+	    __real__ res /= __ieee754_expl (2.0L * __imag__ x);
 	}
       else
 	{
-	  long double sinhix = __ieee754_sinhl (__imag__ x);
-	  long double coshix = __ieee754_coshl (__imag__ x);
+	  long double sinhix, coshix;
+	  if (fabsl (__imag__ x) > LDBL_MIN)
+	    {
+	      sinhix = __ieee754_sinhl (__imag__ x);
+	      coshix = __ieee754_coshl (__imag__ x);
+	    }
+	  else
+	    {
+	      sinhix = __imag__ x;
+	      coshix = 1.0L;
+	    }
 
-	  den = cosrx * cosrx + sinhix * sinhix;
-	  __real__ res = sinrx * cosrx / den;
-	  __imag__ res = sinhix * coshix / den;
+	  if (fabsl (sinhix) > fabsl (cosrx) * ldbl_eps)
+	    den = cosrx * cosrx + sinhix * sinhix;
+	  else
+	    den = cosrx * cosrx;
+	  __real__ res = sinrx * (cosrx / den);
+	  __imag__ res = sinhix * (coshix / den);
 	}
 
       /* __gcc_qmul does not respect -0.0 so we need the following fixup.  */
-      if ((__real__ res == 0.0) && (__real__ x == 0.0))
+      if ((__real__ res == 0.0L) && (__real__ x == 0.0L))
         __real__ res = __real__ x;
 
-      if ((__real__ res == 0.0) && (__imag__ x == 0.0))
+      if ((__real__ res == 0.0L) && (__imag__ x == 0.0L))
         __imag__ res = __imag__ x;
     }