9a3412eea8
casinhf.c catanf.c catanhf.c ccosf.c ccoshf.c cexpf.c cimagf.c clogf.c cpowf.c cprojf.c crealf.c csinf.c csinhf.c csqrtf.c ctanf.c ctanhf.c): New files. * mingwex/Makefile.in (COMPLEX_DISTFILES): Adjust. (COMPLEX_OBJS(: Adjust. * include/complex.h (cabsf, cacosf, cacoshf, cargf, casinf. casinhf, catanf, catanhf, ccosf, ccoshf, cexpf, cimagf, clogf, cpowf, cprojf, crealf, csinf, csinhf, csqrtf, ctanf, ctanhf): Declare.
50 lines
903 B
C
Executable File
50 lines
903 B
C
Executable File
/* catanf.c */
|
|
|
|
/*
|
|
Contributed by Danny Smith
|
|
2004-12-24
|
|
|
|
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)) */
|
|
|
|
float complex
|
|
catanf (float complex Z)
|
|
{
|
|
float complex Res;
|
|
float complex Tmp;
|
|
float x = __real__ Z;
|
|
float y = __imag__ Z;
|
|
|
|
if ( x == 0.0f && (1.0f - fabsf (y)) == 0.0f)
|
|
{
|
|
errno = ERANGE;
|
|
__real__ Res = HUGE_VALF;
|
|
__imag__ Res = HUGE_VALF;
|
|
}
|
|
else if (isinf (hypotf (x, y)))
|
|
{
|
|
__real__ Res = (x > 0 ? M_PI_2 : -M_PI_2);
|
|
__imag__ Res = 0.0f;
|
|
}
|
|
else
|
|
{
|
|
__real__ Tmp = - x;
|
|
__imag__ Tmp = 1.0f - y;
|
|
|
|
__real__ Res = x;
|
|
__imag__ Res = y + 1.0f;
|
|
|
|
Tmp = clogf (Res/Tmp);
|
|
__real__ Res = - 0.5f * __imag__ Tmp;
|
|
__imag__ Res = 0.5f * __real__ Tmp;
|
|
}
|
|
|
|
return Res;
|
|
}
|