about summary refs log tree commit diff
path: root/math/s_clogl.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2012-07-09 11:06:34 +0000
committerJoseph Myers <joseph@codesourcery.com>2012-07-09 11:06:34 +0000
commit638a572eb0d9af9588bf79e14badc1efefe59d99 (patch)
tree4e519d885a916df57a231f058bafe1bc212b1f0f /math/s_clogl.c
parentad41a87fe0777b1500df48609307f8d9d906dfb9 (diff)
downloadglibc-638a572eb0d9af9588bf79e14badc1efefe59d99.tar.gz
glibc-638a572eb0d9af9588bf79e14badc1efefe59d99.tar.xz
glibc-638a572eb0d9af9588bf79e14badc1efefe59d99.zip
Fix clog, clog10 spurious underflow exceptions (bug 14337).
Diffstat (limited to 'math/s_clogl.c')
-rw-r--r--math/s_clogl.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/math/s_clogl.c b/math/s_clogl.c
index 8968eefee3..a393b88a5f 100644
--- a/math/s_clogl.c
+++ b/math/s_clogl.c
@@ -40,25 +40,30 @@ __clogl (__complex__ long double x)
   else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1))
     {
       /* Neither real nor imaginary part is NaN.  */
+      long double absx = fabsl (__real__ x), absy = fabsl (__imag__ x);
       long double d;
       int scale = 0;
 
-      if (fabsl (__real__ x) > LDBL_MAX / 2.0L
-	  || fabsl (__imag__ x) > LDBL_MAX / 2.0L)
+      if (absx > LDBL_MAX / 2.0L)
 	{
 	  scale = -1;
-	  __real__ x = __scalbnl (__real__ x, scale);
-	  __imag__ x = __scalbnl (__imag__ x, scale);
+	  absx = __scalbnl (absx, scale);
+	  absy = (absy >= LDBL_MIN * 2.0L ? __scalbnl (absy, scale) : 0.0L);
 	}
-      else if (fabsl (__real__ x) < LDBL_MIN
-	       && fabsl (__imag__ x) < LDBL_MIN)
+      else if (absy > LDBL_MAX / 2.0L)
+	{
+	  scale = -1;
+	  absx = (absx >= LDBL_MIN * 2.0L ? __scalbnl (absx, scale) : 0.0L);
+	  absy = __scalbnl (absy, scale);
+	}
+      else if (absx < LDBL_MIN && absy < LDBL_MIN)
 	{
 	  scale = LDBL_MANT_DIG;
-	  __real__ x = __scalbnl (__real__ x, scale);
-	  __imag__ x = __scalbnl (__imag__ x, scale);
+	  absx = __scalbnl (absx, scale);
+	  absy = __scalbnl (absy, scale);
 	}
 
-      d = __ieee754_hypotl (__real__ x, __imag__ x);
+      d = __ieee754_hypotl (absx, absy);
 
       __real__ result = __ieee754_logl (d) - scale * M_LN2l;
       __imag__ result = __ieee754_atan2l (__imag__ x, __real__ x);