summaryrefslogtreecommitdiffstats
path: root/winsup/mingw/mingwex/complex/ctan.c
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/mingw/mingwex/complex/ctan.c')
-rw-r--r--winsup/mingw/mingwex/complex/ctan.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/winsup/mingw/mingwex/complex/ctan.c b/winsup/mingw/mingwex/complex/ctan.c
new file mode 100644
index 000000000..a479772a9
--- /dev/null
+++ b/winsup/mingw/mingwex/complex/ctan.c
@@ -0,0 +1,41 @@
+/* ctan.c */
+
+/*
+ Contributed by Danny Smith
+ 2003-10-20
+*/
+
+#include <math.h>
+#include <complex.h>
+#include <errno.h>
+
+
+/* ctan (x + I * y) = (sin (2 * x) + I * sinh(2 * y))
+ / (cos (2 * x) + cosh (2 * y)) */
+
+double complex ctan (double complex Z)
+{
+ double complex Res;
+ double two_I = 2.0 * __imag__ Z;
+ double two_R = 2.0 * __real__ Z;
+ double denom = cos (two_R) + cosh (two_I);
+ if (denom == 0.0)
+ {
+ errno = ERANGE;
+ __real__ Res = HUGE_VAL;
+ __imag__ Res = HUGE_VAL;
+ }
+ else if (isinf (denom))
+ {
+ errno = ERANGE;
+ __real__ Res = 0.0;
+ __imag__ Res = two_I > 0 ? 1.0 : -1.0;
+ }
+ else
+ {
+ __real__ Res = sin (two_R) / denom;
+ __imag__ Res = sinh (two_I) / denom;
+ }
+ return Res;
+}
+