From 638a572eb0d9af9588bf79e14badc1efefe59d99 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Mon, 9 Jul 2012 11:06:34 +0000 Subject: Fix clog, clog10 spurious underflow exceptions (bug 14337). --- math/s_clog.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'math/s_clog.c') diff --git a/math/s_clog.c b/math/s_clog.c index 15e5e9c..2249e86 100644 --- a/math/s_clog.c +++ b/math/s_clog.c @@ -40,25 +40,30 @@ __clog (__complex__ double x) else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1)) { /* Neither real nor imaginary part is NaN. */ + double absx = fabs (__real__ x), absy = fabs (__imag__ x); double d; int scale = 0; - if (fabs (__real__ x) > DBL_MAX / 2.0 - || fabs (__imag__ x) > DBL_MAX / 2.0) + if (absx > DBL_MAX / 2.0) { scale = -1; - __real__ x = __scalbn (__real__ x, scale); - __imag__ x = __scalbn (__imag__ x, scale); + absx = __scalbn (absx, scale); + absy = (absy >= DBL_MIN * 2.0 ? __scalbn (absy, scale) : 0.0); } - else if (fabs (__real__ x) < DBL_MIN - && fabs (__imag__ x) < DBL_MIN) + else if (absy > DBL_MAX / 2.0) + { + scale = -1; + absx = (absx >= DBL_MIN * 2.0 ? __scalbn (absx, scale) : 0.0); + absy = __scalbn (absy, scale); + } + else if (absx < DBL_MIN && absy < DBL_MIN) { scale = DBL_MANT_DIG; - __real__ x = __scalbn (__real__ x, scale); - __imag__ x = __scalbn (__imag__ x, scale); + absx = __scalbn (absx, scale); + absy = __scalbn (absy, scale); } - d = __ieee754_hypot (__real__ x, __imag__ x); + d = __ieee754_hypot (absx, absy); __real__ result = __ieee754_log (d) - scale * M_LN2; __imag__ result = __ieee754_atan2 (__imag__ x, __real__ x); -- cgit v1.1