summaryrefslogtreecommitdiff
path: root/lib/libm/catanl.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libm/catanl.c')
-rw-r--r--lib/libm/catanl.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/libm/catanl.c b/lib/libm/catanl.c
new file mode 100644
index 00000000..949dc3d9
--- /dev/null
+++ b/lib/libm/catanl.c
@@ -0,0 +1,34 @@
+#include <float.h>
+#include "__complex.h"
+
+long double complex catanl(long double complex z)
+{
+ long double complex w;
+ long double a, t, x, x2, y;
+
+ x = creall(z);
+ y = cimagl(z);
+
+ if ((x == 0.0L) && (y > 1.0L))
+ goto overflow;
+
+ x2 = x * x;
+ a = 1.0L - x2 - (y * y);
+ if (a == 0.0)
+ goto overflow;
+
+ t = 0.5L * atan2l(2.0L * x, a);
+ w = redupil(t);
+
+ t = y - 1.0L;
+ a = x2 + (t * t);
+ if (a == 0.0L)
+ goto overflow;
+
+ t = y + 1.0L;
+ a = (x2 + (t * t)) / a;
+ return w + (0.25L * logl(a)) * I;
+
+overflow:
+ return LDBL_MAX + LDBL_MAX * I;
+}