aboutsummaryrefslogtreecommitdiff
path: root/math/s_catan.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2013-05-01 10:07:00 +0000
committerJoseph Myers <joseph@codesourcery.com>2013-05-01 10:07:00 +0000
commit10de07f5fdd9eaf3a808d4461401f5b661095614 (patch)
tree844a1ed48df767e65d46a429f0e1b062e0e2fad5 /math/s_catan.c
parentcb4d54147e620f4267d1c675bf2daec0a8e7c809 (diff)
downloadglibc-10de07f5fdd9eaf3a808d4461401f5b661095614.zip
glibc-10de07f5fdd9eaf3a808d4461401f5b661095614.tar.gz
glibc-10de07f5fdd9eaf3a808d4461401f5b661095614.tar.bz2
Fix catan, catanh spurious underflows (bug 15423).
Diffstat (limited to 'math/s_catan.c')
-rw-r--r--math/s_catan.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/math/s_catan.c b/math/s_catan.c
index 3a041f2..4da0a0d 100644
--- a/math/s_catan.c
+++ b/math/s_catan.c
@@ -77,7 +77,7 @@ __catan (__complex__ double x)
}
else
{
- double r2, num, den, f, absx, absy;
+ double den, absx, absy;
absx = fabs (__real__ x);
absy = fabs (__imag__ x);
@@ -88,10 +88,10 @@ __catan (__complex__ double x)
absy = t;
}
- if (absx >= 1.0)
- den = (1.0 - absx) * (1.0 + absx) - absy * absy;
- else if (absx >= 0.75 && absy < DBL_EPSILON / 2.0)
+ if (absy < DBL_EPSILON / 2.0)
den = (1.0 - absx) * (1.0 + absx);
+ else if (absx >= 1.0)
+ den = (1.0 - absx) * (1.0 + absx) - absy * absy;
else if (absx >= 0.75 || absy >= 0.5)
den = -__x2y2m1 (absx, absy);
else
@@ -99,21 +99,31 @@ __catan (__complex__ double x)
__real__ res = 0.5 * __ieee754_atan2 (2.0 * __real__ x, den);
- r2 = __real__ x * __real__ x;
+ if (fabs (__imag__ x) == 1.0
+ && fabs (__real__ x) < DBL_EPSILON * DBL_EPSILON)
+ __imag__ res = (__copysign (0.5, __imag__ x)
+ * (M_LN2 - __ieee754_log (fabs (__real__ x))));
+ else
+ {
+ double r2 = 0.0, num, f;
- num = __imag__ x + 1.0;
- num = r2 + num * num;
+ if (fabs (__real__ x) >= DBL_EPSILON * DBL_EPSILON)
+ r2 = __real__ x * __real__ x;
- den = __imag__ x - 1.0;
- den = r2 + den * den;
+ num = __imag__ x + 1.0;
+ num = r2 + num * num;
- f = num / den;
- if (f < 0.5)
- __imag__ res = 0.25 * __ieee754_log (f);
- else
- {
- num = 4.0 * __imag__ x;
- __imag__ res = 0.25 * __log1p (num / den);
+ den = __imag__ x - 1.0;
+ den = r2 + den * den;
+
+ f = num / den;
+ if (f < 0.5)
+ __imag__ res = 0.25 * __ieee754_log (f);
+ else
+ {
+ num = 4.0 * __imag__ x;
+ __imag__ res = 0.25 * __log1p (num / den);
+ }
}
}