diff options
Diffstat (limited to 'lib/libm/catanf.c')
| -rw-r--r-- | lib/libm/catanf.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/libm/catanf.c b/lib/libm/catanf.c new file mode 100644 index 00000000..16d480e0 --- /dev/null +++ b/lib/libm/catanf.c @@ -0,0 +1,35 @@ +#include <float.h> +#include "__complex.h" + +float complex catanf(float complex z) +{ + float complex w; + float a, t, x, x2, y; + + x = crealf(z); + y = cimagf(z); + + if ((x == 0.0f) && (y > 1.0f)) + goto overflow; + + x2 = x * x; + a = 1.0f - x2 - (y * y); + if (a == 0.0f) + goto overflow; + + t = 0.5f * atan2f(2.0f * x, a); + w = redupif(t); + + t = y - 1.0f; + a = x2 + (t * t); + if (a == 0.0f) + goto overflow; + + t = y + 1.0f; + a = (x2 + (t * t)) / a; + + return w + (0.25f * logf(a)) * I; + +overflow: + return FLT_MAX + FLT_MAX * I; +} |
