blob: eee1e8fa71095df0d6a1b82e6295ada0d0b72f21 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/* catan.c */
/*
Contributed by Danny Smith
2003-10-17
FIXME: This needs some serious numerical analysis.
*/
#include <math.h>
#include <complex.h>
#include <errno.h>
/* catan (z) = -I/2 * clog ((I + z) / (I - z)) */
double complex
catan (double complex Z)
{
double complex Res;
double complex Tmp;
double x = __real__ Z;
double y = __imag__ Z;
if ( x == 0.0 && (1.0 - fabs (y)) == 0.0)
{
errno = ERANGE;
__real__ Res = HUGE_VAL;
__imag__ Res = HUGE_VAL;
}
else if (isinf (_hypot (x, y)))
{
__real__ Res = (x > 0 ? M_PI_2 : -M_PI_2);
__imag__ Res = 0.0;
}
else
{
__real__ Tmp = - x;
__imag__ Tmp = 1.0 - y;
__real__ Res = x;
__imag__ Res = y + 1.0;
Tmp = clog (Res/Tmp);
__real__ Res = - 0.5 * __imag__ Tmp;
__imag__ Res = 0.5 * __real__ Tmp;
}
return Res;
}
|