3c7a7a5fca
* include/complex.h: New file. * mingwex/complex: New directory. * mingwex/complex/cabs.c: New file. * mingwex/complex/cacos.c: New file. * mingwex/complex/cacosh.c: New file. * mingwex/complex/casin.c: New file. * mingwex/complex/casinh.c: New file. * mingwex/complex/catan.c: New file. * mingwex/complex/catanh.c: New file. * mingwex/complex/ccos.c: New file. * mingwex/complex/ccosh.c: New file. * mingwex/complex/cexp.c: New file. * mingwex/complex/cimag.c: New file. * mingwex/complex/clog.c: New file. * mingwex/complex/cpow.c: New file. * mingwex/complex/cproj.c: New file. * mingwex/complex/creal.c: New file. * mingwex/complex/csin.c: New file. * mingwex/complex/csinh.c: New file. * mingwex/complex/csqrt.c: New file. * mingwex/complex/ctan.c: New file. * mingwex/complex/ctanh.c: New file. * mingwex/Makefile.in (COMPLEX_DISTFILES): New list of files. (dist): Use it. (COMPLEX_OBJS): New list of objects. (LIB_OBJS): Include it in the library.
50 lines
895 B
C
50 lines
895 B
C
/* 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;
|
|
}
|