aboutsummaryrefslogtreecommitdiff
path: root/math/s_catanf.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_catanf.c
parentcb4d54147e620f4267d1c675bf2daec0a8e7c809 (diff)
downloadglibc-10de07f5fdd9eaf3a808d4461401f5b661095614.tar
glibc-10de07f5fdd9eaf3a808d4461401f5b661095614.tar.gz
glibc-10de07f5fdd9eaf3a808d4461401f5b661095614.tar.bz2
glibc-10de07f5fdd9eaf3a808d4461401f5b661095614.zip
Fix catan, catanh spurious underflows (bug 15423).
Diffstat (limited to 'math/s_catanf.c')
-rw-r--r--math/s_catanf.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/math/s_catanf.c b/math/s_catanf.c
index 698e2af461..0713565c86 100644
--- a/math/s_catanf.c
+++ b/math/s_catanf.c
@@ -78,7 +78,7 @@ __catanf (__complex__ float x)
}
else
{
- float r2, num, den, f, absx, absy;
+ float den, absx, absy;
absx = fabsf (__real__ x);
absy = fabsf (__imag__ x);
@@ -89,10 +89,10 @@ __catanf (__complex__ float x)
absy = t;
}
- if (absx >= 1.0f)
- den = (1.0f - absx) * (1.0f + absx) - absy * absy;
- else if (absx >= 0.75f && absy < FLT_EPSILON / 2.0f)
+ if (absy < FLT_EPSILON / 2.0f)
den = (1.0f - absx) * (1.0f + absx);
+ else if (absx >= 1.0f)
+ den = (1.0f - absx) * (1.0f + absx) - absy * absy;
else if (absx >= 0.75f || absy >= 0.5f)
den = -__x2y2m1f (absx, absy);
else
@@ -100,21 +100,32 @@ __catanf (__complex__ float x)
__real__ res = 0.5f * __ieee754_atan2f (2.0f * __real__ x, den);
- r2 = __real__ x * __real__ x;
+ if (fabsf (__imag__ x) == 1.0f
+ && fabsf (__real__ x) < FLT_EPSILON * FLT_EPSILON)
+ __imag__ res = (__copysignf (0.5f, __imag__ x)
+ * ((float) M_LN2
+ - __ieee754_logf (fabsf (__real__ x))));
+ else
+ {
+ float r2 = 0.0f, num, f;
- num = __imag__ x + 1.0f;
- num = r2 + num * num;
+ if (fabsf (__real__ x) >= FLT_EPSILON * FLT_EPSILON)
+ r2 = __real__ x * __real__ x;
- den = __imag__ x - 1.0f;
- den = r2 + den * den;
+ num = __imag__ x + 1.0f;
+ num = r2 + num * num;
- f = num / den;
- if (f < 0.5f)
- __imag__ res = 0.25f * __ieee754_logf (f);
- else
- {
- num = 4.0f * __imag__ x;
- __imag__ res = 0.25f * __log1pf (num / den);
+ den = __imag__ x - 1.0f;
+ den = r2 + den * den;
+
+ f = num / den;
+ if (f < 0.5f)
+ __imag__ res = 0.25f * __ieee754_logf (f);
+ else
+ {
+ num = 4.0f * __imag__ x;
+ __imag__ res = 0.25f * __log1pf (num / den);
+ }
}
}