aboutsummaryrefslogtreecommitdiff
path: root/math/s_catanh.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_catanh.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_catanh.c')
-rw-r--r--math/s_catanh.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/math/s_catanh.c b/math/s_catanh.c
index 5248cbc..54be9f9 100644
--- a/math/s_catanh.c
+++ b/math/s_catanh.c
@@ -72,24 +72,33 @@ __catanh (__complex__ double x)
}
else
{
- double i2 = __imag__ x * __imag__ x;
+ if (fabs (__real__ x) == 1.0
+ && fabs (__imag__ x) < DBL_EPSILON * DBL_EPSILON)
+ __real__ res = (__copysign (0.5, __real__ x)
+ * (M_LN2 - __ieee754_log (fabs (__imag__ x))));
+ else
+ {
+ double i2 = 0.0;
+ if (fabs (__imag__ x) >= DBL_EPSILON * DBL_EPSILON)
+ i2 = __imag__ x * __imag__ x;
- double num = 1.0 + __real__ x;
- num = i2 + num * num;
+ double num = 1.0 + __real__ x;
+ num = i2 + num * num;
- double den = 1.0 - __real__ x;
- den = i2 + den * den;
+ double den = 1.0 - __real__ x;
+ den = i2 + den * den;
- double f = num / den;
- if (f < 0.5)
- __real__ res = 0.25 * __ieee754_log (f);
- else
- {
- num = 4.0 * __real__ x;
- __real__ res = 0.25 * __log1p (num / den);
+ double f = num / den;
+ if (f < 0.5)
+ __real__ res = 0.25 * __ieee754_log (f);
+ else
+ {
+ num = 4.0 * __real__ x;
+ __real__ res = 0.25 * __log1p (num / den);
+ }
}
- double absx, absy;
+ double absx, absy, den;
absx = fabs (__real__ x);
absy = fabs (__imag__ x);
@@ -100,10 +109,10 @@ __catanh (__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