diff options
author | Danny Smith <dannysmith@users.sourceforge.net> | 2005-01-10 05:03:55 +0000 |
---|---|---|
committer | Danny Smith <dannysmith@users.sourceforge.net> | 2005-01-10 05:03:55 +0000 |
commit | 4073a59300a4411813a4a1c4de5e0c4e3d77ee09 (patch) | |
tree | be52f78e7dc02863f8ccfa8141421a8b5b1b437a /winsup/mingw/mingwex | |
parent | 76eb61923900be1b6fd4f83bb62f48670fe7293c (diff) | |
download | newlib-4073a59300a4411813a4a1c4de5e0c4e3d77ee09.zip newlib-4073a59300a4411813a4a1c4de5e0c4e3d77ee09.tar.gz newlib-4073a59300a4411813a4a1c4de5e0c4e3d77ee09.tar.bz2 |
* mingwex/complex/(cabsl.c cacosl.c cacoshl.c cargl.c casinl.c
casinhl.c catanl.c catanhl.c ccosl.c ccoshl.c cexpl.c cimagl.c
clogl.c cpowl.c cprojl.c creall.c csinl.c csinhl.c csqrtl.c
ctanl.c ctanhl.c): New files.
* mingwex/Makefile.in (COMPLEX_DISTFILES): Adjust.
(COMPLEX_OBJS): Adjust.
* include/complex.h (cabsl, cacosl, cacoshl, cargl, casinf.
casinhl, catanl, catanhl, ccosl, ccoshl, cexpl, cimagl, clogl,
cpowl, cprojl, creall, csinl, csinhl, csqrtl, ctanl, ctanhl):
Declare.
Diffstat (limited to 'winsup/mingw/mingwex')
22 files changed, 618 insertions, 12 deletions
diff --git a/winsup/mingw/mingwex/Makefile.in b/winsup/mingw/mingwex/Makefile.in index 66659a6..e79df9a 100644 --- a/winsup/mingw/mingwex/Makefile.in +++ b/winsup/mingw/mingwex/Makefile.in @@ -70,12 +70,15 @@ STDIO_DISTFILES = \ vfscanf.c vfwscanf.c vscanf.c vsscanf.c vswscanf.c vwscanf.c COMPLEX_DISTFILES = \ - cabs.c cabsf.c cacos.c cacosf.c cacosh.c cacoshf.c carg.c \ - cargf.c casin.c casinf.c casinh.c casinhf.c catan.c catanf.c \ - catanh.c catanhf.c ccos.c ccosf.c ccosh.c ccoshf.c cexp.c \ - cexpf.c cimag.c cimagf.c clog.c clogf.c cpow.c cpowf.c cproj.c \ - cprojf.c creal.c crealf.c csin.c csinf.c csinh.c csinhf.c \ - csqrt.c csqrtf.c ctan.c ctanf.c ctanh.c ctanhf.c + cabs.c cabsf.c cabsl.c cacos.c cacosf.c cacosl.c cacosh.c \ + cacoshf.c cacoshl.c carg.c cargf.c cargl.c casin.c casinf.c \ + casinl.c casinh.c casinhf.c casinhl.c catan.c catanf.c catanl.c \ + catanh.c catanhf.c catanhl.c ccos.c ccosf.c ccosl.c ccosh.c \ + ccoshf.c ccoshl.c cexp.c cexpf.c cexpl.c cimag.c cimagf.c \ + cimagl.c clog.c clogf.c clogl.c cpow.c cpowf.c cpowl.c cproj.c \ + cprojf.c cprojl.c creal.c crealf.c creall.c csin.c csinf.c \ + csinl.c csinh.c csinhf.c csinhl.c csqrt.c csqrtf.c csqrtl.c \ + ctan.c ctanf.c ctanl.c ctanh.c ctanhf.c ctanhl.c CC = @CC@ # FIXME: Which is it, CC or CC_FOR_TARGET? @@ -159,12 +162,15 @@ POSIX_OBJS = \ REPLACE_OBJS = \ mingw-aligned-malloc.o mingw-fseek.o COMPLEX_OBJS = \ - cabs.o cabsf.o cacos.o cacosf.o cacosh.o cacoshf.o carg.o \ - cargf.o casin.o casinf.o casinh.o casinhf.o catan.o catanf.o \ - catanh.o catanhf.o ccos.o ccosf.o ccosh.o ccoshf.o cexp.o \ - cexpf.o cimag.o cimagf.o clog.o clogf.o cpow.o cpowf.o cproj.o \ - cprojf.o creal.o crealf.o csin.o csinf.o csinh.o csinhf.o \ - csqrt.o csqrtf.o ctan.o ctanf.o ctanh.o ctanhf.o + cabs.o cabsf.o cabsl.o cacos.o cacosf.o cacosl.o cacosh.o \ + cacoshf.o cacoshl.o carg.o cargf.o cargl.o casin.o casinf.o \ + casinl.o casinh.o casinhf.o casinhl.o catan.o catanf.o catanl.o \ + catanh.o catanhf.o catanhl.o ccos.o ccosf.o ccosl.o ccosh.o \ + ccoshf.o ccoshl.o cexp.o cexpf.o cexpl.o cimag.o cimagf.o \ + cimagl.o clog.o clogf.o clogl.o cpow.o cpowf.o cpowl.o cproj.o \ + cprojf.o cprojl.o creal.o crealf.o creall.o csin.o csinf.o \ + csinl.o csinh.o csinhf.o csinhl.o csqrt.o csqrtf.o csqrtl.o \ + ctan.o ctanf.o ctanl.o ctanh.o ctanhf.o ctanhl.o LIB_OBJS = $(Q8_OBJS) $(STDLIB_OBJS) $(STDLIB_STUB_OBJS) \ $(STDIO_OBJS) $(MATH_OBJS) $(FENV_OBJS) \ diff --git a/winsup/mingw/mingwex/complex/cabsl.c b/winsup/mingw/mingwex/complex/cabsl.c new file mode 100755 index 0000000..3312465 --- /dev/null +++ b/winsup/mingw/mingwex/complex/cabsl.c @@ -0,0 +1,7 @@ +#include <math.h> +#include <complex.h> + +long double cabsl (long double complex Z) +{ + return hypotl ( __real__ Z, __imag__ Z); +} diff --git a/winsup/mingw/mingwex/complex/cacoshl.c b/winsup/mingw/mingwex/complex/cacoshl.c new file mode 100755 index 0000000..7f482c4 --- /dev/null +++ b/winsup/mingw/mingwex/complex/cacoshl.c @@ -0,0 +1,39 @@ +/* + cacoshl.c + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +#if 0 +/* cacosh (z) = I * cacos (z) */ +long double complex cacoshl (long double complex Z) +{ + long double complex Tmp; + long double complex Res; + + Tmp = cacosl (Z); + __real__ Res = -__imag__ Tmp; + __imag__ Res = __real__ Tmp; + return Res; +} + +#else + +/* cacosh (z) = I * cacos (z) = I * (pi/2 - casin (z)) */ +#ifndef _M_PI_2L +#define _M_PI_2L 1.5707963267948966192313L +#endif +long double complex cacoshl (long double complex Z) +{ + long double complex Tmp; + long double complex Res; + + Tmp = casinl (Z); + __real__ Res = __imag__ Tmp; + __imag__ Res = _M_PI_2L - __real__ Tmp; + return Res; +} +#endif diff --git a/winsup/mingw/mingwex/complex/cacosl.c b/winsup/mingw/mingwex/complex/cacosl.c new file mode 100755 index 0000000..c8e0b6e --- /dev/null +++ b/winsup/mingw/mingwex/complex/cacosl.c @@ -0,0 +1,66 @@ +/* + cacosl.c + Contributed by Danny Smith + 2004-01-04 +*/ + +#include <math.h> +#include <complex.h> + +#if 0 +/* cacos (Z) = -I * clog(Z + I * csqrt(1 - Z * Z)) */ + +long double complex cacosl (long double complex Z) +{ + long double complex Res; + long double x, y; + + x = __real__ Z; + y = __imag__ Z; + + if (y == 0.0L) + { + __real__ Res = acosl (x); + __imag__ Res = 0.0L; + } + + else + { + long double complex ZZ; + /* Z * Z = ((x - y) * (x + y)) + (2.0 * x * y) * I */ + /* caculate 1 - Z * Z */ + __real__ ZZ = 1.0L - (x - y) * (x + y); + __imag__ ZZ = -2.0L * x * y; + + + Res = csqrtl(ZZ); + + /* calculate ZZ + I * sqrt (ZZ) */ + + __real__ ZZ = x - __imag__ Res; + __imag__ ZZ = y + __real__ Res; + + ZZ = clogl(ZZ); + + /* mult by -I */ + + __real__ Res = __imag__ ZZ; + __imag__ Res = - __real__ ZZ; + } + return Res; +} + +#else + +/* cacos ( Z ) = pi/2 - casin ( Z ) */ +#ifndef _M_PI_2L +#define _M_PI_2L 1.5707963267948966192313L +#endif +long double complex cacosl (long double complex Z) +{ + long double complex Res = casinl (Z); + __real__ Res = _M_PI_2L - __real__ Res; + __imag__ Res = - __imag__ Res; + return Res; +} +#endif diff --git a/winsup/mingw/mingwex/complex/cargl.c b/winsup/mingw/mingwex/complex/cargl.c new file mode 100755 index 0000000..179dae7 --- /dev/null +++ b/winsup/mingw/mingwex/complex/cargl.c @@ -0,0 +1,8 @@ +#include <complex.h> +long double __attribute__ ((const)) cargl (long double _Complex _Z) +{ + long double res; + __asm__ ("fpatan;" + : "=t" (res) : "0" (__real__ _Z), "u" (__imag__ _Z) : "st(1)"); + return res; +} diff --git a/winsup/mingw/mingwex/complex/casinhl.c b/winsup/mingw/mingwex/complex/casinhl.c new file mode 100755 index 0000000..348bf80 --- /dev/null +++ b/winsup/mingw/mingwex/complex/casinhl.c @@ -0,0 +1,23 @@ +/* + casinhl.c + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +/* casinh (z) = -I casin (I * z) */ + +long double complex casinhl (long double complex Z) +{ + long double complex Tmp; + long double complex Res; + + __real__ Tmp = - __imag__ Z; + __imag__ Tmp = __real__ Z; + Tmp = casinl (Tmp); + __real__ Res = __imag__ Tmp; + __imag__ Res = - __real__ Tmp; + return Res; +} diff --git a/winsup/mingw/mingwex/complex/casinl.c b/winsup/mingw/mingwex/complex/casinl.c new file mode 100755 index 0000000..3093fa5 --- /dev/null +++ b/winsup/mingw/mingwex/complex/casinl.c @@ -0,0 +1,48 @@ +/* + casinl.c + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +/* casin (Z ) = -I * clog(I * Z + csqrt (1.0 - Z * Z))) */ + +long double complex casinl (long double complex Z) +{ + long double complex Res; + long double x, y; + + x = __real__ Z; + y = __imag__ Z; + + if (y == 0.0L) + { + __real__ Res = asinl (x); + __imag__ Res = 0.0L; + } + else /* -I * clog(I * Z + csqrt(1.0 - Z * Z))) */ + { + long double complex ZZ; + + /* Z * Z = ((x - y) * (x + y)) + (2.0 * x * y) * I */ + /* calculate 1 - Z * Z */ + __real__ ZZ = 1.0L - (x - y) * (x + y); + __imag__ ZZ = -2.0L * x * y; + ZZ = csqrtl (ZZ); + + + /* add I * Z to ZZ */ + + __real__ ZZ -= y; + __imag__ ZZ += x; + + ZZ = clogl (ZZ); + + /* mult by -I */ + __real__ Res = __imag__ ZZ; + __imag__ Res = - __real__ ZZ; + } + return (Res); +} diff --git a/winsup/mingw/mingwex/complex/catanhl.c b/winsup/mingw/mingwex/complex/catanhl.c new file mode 100755 index 0000000..50a3be9 --- /dev/null +++ b/winsup/mingw/mingwex/complex/catanhl.c @@ -0,0 +1,23 @@ +/* catanhl.c */ +/* + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +/* catanh (z) = -I * catan (I * z) */ + +long double complex catanhl (long double complex Z) +{ + long double complex Tmp; + long double complex Res; + + __real__ Tmp = - __imag__ Z; + __imag__ Tmp = __real__ Z; + Tmp = catanl (Tmp); + __real__ Res = __imag__ Tmp; + __imag__ Res = - __real__ Tmp; + return Res; +} diff --git a/winsup/mingw/mingwex/complex/catanl.c b/winsup/mingw/mingwex/complex/catanl.c new file mode 100755 index 0000000..1fd6268 --- /dev/null +++ b/winsup/mingw/mingwex/complex/catanl.c @@ -0,0 +1,53 @@ +/* catanl.c */ + +/* + Contributed by Danny Smith + 2005-01-04 + + 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)) */ + +#ifndef _M_PI_2L +#define _M_PI_2L 1.5707963267948966192313L +#endif + +long double complex +catanl (long double complex Z) +{ + long double complex Res; + long double complex Tmp; + long double x = __real__ Z; + long double y = __imag__ Z; + + if ( x == 0.0L && (1.0L - fabsl (y)) == 0.0L) + { + errno = ERANGE; + __real__ Res = HUGE_VALL; + __imag__ Res = HUGE_VALL; + } + else if (isinf (hypotl (x, y))) + { + __real__ Res = (x > 0 ? _M_PI_2L : -_M_PI_2L); + __imag__ Res = 0.0L; + } + else + { + __real__ Tmp = - x; + __imag__ Tmp = 1.0L - y; + + __real__ Res = x; + __imag__ Res = y + 1.0L; + + Tmp = clogl (Res/Tmp); + __real__ Res = - 0.5L * __imag__ Tmp; + __imag__ Res = 0.5L * __real__ Tmp; + } + + return Res; +} diff --git a/winsup/mingw/mingwex/complex/ccoshl.c b/winsup/mingw/mingwex/complex/ccoshl.c new file mode 100755 index 0000000..0fb2526 --- /dev/null +++ b/winsup/mingw/mingwex/complex/ccoshl.c @@ -0,0 +1,19 @@ +/* + ccoshl.c + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +/* ccosh (x + I * y) = cosh (x) * cos (y) + + I * (sinh (x) * sin (y)) */ + +long double complex ccoshl (long double complex Z) +{ + long double complex Res; + __real__ Res = coshl (__real__ Z) * cosl (__imag__ Z); + __imag__ Res = sinhl (__real__ Z) * sinl (__imag__ Z); + return Res; +} diff --git a/winsup/mingw/mingwex/complex/ccosl.c b/winsup/mingw/mingwex/complex/ccosl.c new file mode 100755 index 0000000..981fdf0 --- /dev/null +++ b/winsup/mingw/mingwex/complex/ccosl.c @@ -0,0 +1,20 @@ +/* + ccosl.c + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +/* ccos (x + I * y) = cos (x) * cosh (y) + + I * (sin (x) * sinh (y)) */ + + +long double complex ccosl (long double complex Z) +{ + long double complex Res; + __real__ Res = cosl (__real__ Z) * coshl ( __imag__ Z); + __imag__ Res = -sinl (__real__ Z) * sinhl ( __imag__ Z); + return Res; +} diff --git a/winsup/mingw/mingwex/complex/cexpl.c b/winsup/mingw/mingwex/complex/cexpl.c new file mode 100755 index 0000000..9f2ed26 --- /dev/null +++ b/winsup/mingw/mingwex/complex/cexpl.c @@ -0,0 +1,19 @@ +/* + cexpl.c + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +/* cexp (x + I * y) = exp (x) * cos (y) + I * exp (x) * sin (y) */ + +long double complex cexpl (long double complex Z) +{ + long double complex Res; + long double rho = expl (__real__ Z); + __real__ Res = rho * cosl(__imag__ Z); + __imag__ Res = rho * sinl(__imag__ Z); + return Res; +} diff --git a/winsup/mingw/mingwex/complex/cimagl.c b/winsup/mingw/mingwex/complex/cimagl.c new file mode 100755 index 0000000..9b023b4 --- /dev/null +++ b/winsup/mingw/mingwex/complex/cimagl.c @@ -0,0 +1,5 @@ +#include <complex.h> +long double __attribute__ ((const)) cimagl (long double complex _Z) +{ + return __imag__ _Z; +} diff --git a/winsup/mingw/mingwex/complex/clogl.c b/winsup/mingw/mingwex/complex/clogl.c new file mode 100755 index 0000000..0114c91 --- /dev/null +++ b/winsup/mingw/mingwex/complex/clogl.c @@ -0,0 +1,19 @@ +/* + clogl.c + Contributed by Danny Smith + 2005-01-04 +*/ + +/* clog (x + I * y) = log (hypot (x, y)) + I * atan2 (y, x) */ + +#include <math.h> +#include <complex.h> + +long double complex clogl (long double complex Z) +{ + long double complex Res; + __real__ Res = logl (hypotl (__real__ Z, __imag__ Z)); + __imag__ Res = cargl (Z); + return Res; +} + diff --git a/winsup/mingw/mingwex/complex/cpowl.c b/winsup/mingw/mingwex/complex/cpowl.c new file mode 100755 index 0000000..c614a6d --- /dev/null +++ b/winsup/mingw/mingwex/complex/cpowl.c @@ -0,0 +1,43 @@ +/* cpowl.c */ +/* + Contributed by Danny Smith + 2005-01-04 +*/ + +/* cpow(X, Y) = cexp(X * clog(Y)) */ + +#include <math.h> +#include <complex.h> + +long double complex cpowl (long double complex X, long double complex Y) +{ + long double complex Res; + long double i; + long double r = hypotl (__real__ X, __imag__ X); + if (r == 0.0L) + { + __real__ Res = __imag__ Res = 0.0L; + } + else + { + long double rho; + long double theta; + i = cargl (X); + theta = i * __real__ Y; + + if (__imag__ Y == 0.0L) + /* This gives slightly more accurate results in these cases. */ + rho = powl (r, __real__ Y); + else + { + r = logl (r); + /* rearrangement of cexp(X * clog(Y)) */ + theta += r * __imag__ Y; + rho = expl (r * __real__ Y - i * __imag__ Y); + } + + __real__ Res = rho * cosl (theta); + __imag__ Res = rho * sinl (theta); + } + return Res; +} diff --git a/winsup/mingw/mingwex/complex/cprojl.c b/winsup/mingw/mingwex/complex/cprojl.c new file mode 100755 index 0000000..224d26f --- /dev/null +++ b/winsup/mingw/mingwex/complex/cprojl.c @@ -0,0 +1,22 @@ +/* + cprojl.c + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +/* Return the value of the projection onto the Riemann sphere.*/ + +long double complex cprojl (long double complex Z) +{ + complex long double Res = Z; + if (isinf (__real__ Z) || isinf (__imag__ Z)) + { + __real__ Res = HUGE_VALL; + __imag__ Res = copysignl (0.0L, __imag__ Z); + } + return Res; +} + diff --git a/winsup/mingw/mingwex/complex/creall.c b/winsup/mingw/mingwex/complex/creall.c new file mode 100755 index 0000000..62470d9 --- /dev/null +++ b/winsup/mingw/mingwex/complex/creall.c @@ -0,0 +1,5 @@ +#include <complex.h> +long double __attribute__ ((const)) creall (long double complex _Z) +{ + return __real__ _Z; +} diff --git a/winsup/mingw/mingwex/complex/csinhl.c b/winsup/mingw/mingwex/complex/csinhl.c new file mode 100755 index 0000000..187ccf0 --- /dev/null +++ b/winsup/mingw/mingwex/complex/csinhl.c @@ -0,0 +1,20 @@ +/* csinhl.c */ +/* + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +/* csinh (x + I * y) = sinh (x) * cos (y) + + I * (cosh (x) * sin (y)) */ + + +long double complex csinhl (long double complex Z) +{ + long double complex Res; + __real__ Res = sinhl (__real__ Z) * cosl (__imag__ Z); + __imag__ Res = coshl (__real__ Z) * sinl (__imag__ Z); + return Res; +} diff --git a/winsup/mingw/mingwex/complex/csinl.c b/winsup/mingw/mingwex/complex/csinl.c new file mode 100755 index 0000000..2a98c7c --- /dev/null +++ b/winsup/mingw/mingwex/complex/csinl.c @@ -0,0 +1,21 @@ +/* csinl.c */ + +/* + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +/* csin (x + I * y) = sin (x) * cosh (y) + + I * (cos (x) * sinh (y)) */ + +long double complex csinl (long double complex Z) +{ + long double complex Res; + __real__ Res = sinl (__real__ Z) * coshl ( __imag__ Z); + __imag__ Res = cosl (__real__ Z) * sinhl ( __imag__ Z); + return Res; +} + diff --git a/winsup/mingw/mingwex/complex/csqrtl.c b/winsup/mingw/mingwex/complex/csqrtl.c new file mode 100755 index 0000000..f058b21 --- /dev/null +++ b/winsup/mingw/mingwex/complex/csqrtl.c @@ -0,0 +1,55 @@ +/* csqrtl.c */ +/* + Contributed by Danny Smith + 2005-01-04 +*/ + +#include <math.h> +#include <complex.h> + +long double complex csqrtl (long double complex Z) +{ + long double complex Res; + long double r; + long double x = __real__ Z; + long double y = __imag__ Z; + + if (y == 0.0L) + { + if (x < 0.0L) + { + __real__ Res = 0.0L; + __imag__ Res = sqrtl (-x); + } + else + { + __real__ Res = sqrtl (x); + __imag__ Res = 0.0L; + } + } + + else if (x == 0.0L) + { + r = sqrtl(0.5L * fabsl (y)); + __real__ Res = y > 0 ? r : -r; + __imag__ Res = r; + } + + else + { + long double t = sqrtl (2.0L * (hypotl (__real__ Z, __imag__ Z) + fabsl (x))); + long double u = t / 2.0L; + if ( x > 0.0L) + { + __real__ Res = u; + __imag__ Res = y / t; + } + else + { + __real__ Res = fabsl (y / t); + __imag__ Res = y < 0 ? -u : u; + } + } + + return Res; +} diff --git a/winsup/mingw/mingwex/complex/ctanhl.c b/winsup/mingw/mingwex/complex/ctanhl.c new file mode 100755 index 0000000..050b636 --- /dev/null +++ b/winsup/mingw/mingwex/complex/ctanhl.c @@ -0,0 +1,44 @@ +/* ctanhl.c */ + +/* + Contributed by Danny Smith + 2005-01-04 +*/ + + +#include <math.h> +#include <complex.h> +#include <errno.h> + +/* + ctanh (x + I * y) = (sinh (2 * x) + sin (2 * y) * I ) + / (cosh (2 * x) + cos (2 * y)) . +*/ + +long double complex +ctanhl (long double complex Z) +{ + long double complex Res; + long double two_R = 2.0L * __real__ Z; + long double two_I = 2.0L * __imag__ Z; + long double denom = coshl (two_R) + cosl (two_I); + + if (denom == 0.0L) + { + errno = ERANGE; + __real__ Res = HUGE_VALL; + __imag__ Res = HUGE_VALL; + } + else if (isinf (denom)) + { + errno = ERANGE; + __real__ Res = two_R > 0 ? 1.0L : -1.0L; + __imag__ Res = 0.0L; + } + else + { + __real__ Res = sinhl (two_R) / denom; + __imag__ Res = sinl (two_I) / denom; + } + return Res; +} diff --git a/winsup/mingw/mingwex/complex/ctanl.c b/winsup/mingw/mingwex/complex/ctanl.c new file mode 100755 index 0000000..7d30761 --- /dev/null +++ b/winsup/mingw/mingwex/complex/ctanl.c @@ -0,0 +1,41 @@ +/* ctanl.c */ + +/* + Contributed by Danny Smith + 2005-01-04 +*/ + +#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)) */ + +long double complex ctanl (long double complex Z) +{ + long double complex Res; + long double two_I = 2.0L * __imag__ Z; + long double two_R = 2.0L * __real__ Z; + long double denom = cosl (two_R) + coshl (two_I); + if (denom == 0.0L) + { + errno = ERANGE; + __real__ Res = HUGE_VALL; + __imag__ Res = HUGE_VALL; + } + else if (isinf (denom)) + { + errno = ERANGE; + __real__ Res = 0.0; + __imag__ Res = two_I > 0 ? 1.0L : -1.0L; + } + else + { + __real__ Res = sinl (two_R) / denom; + __imag__ Res = sinhl (two_I) / denom; + } + return Res; +} + |