* 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.
This commit is contained in:
Danny Smith 2005-01-10 05:03:55 +00:00
parent 76eb619239
commit 4073a59300
24 changed files with 682 additions and 14 deletions

View File

@ -1,3 +1,16 @@
2005-01-10 Danny Smith <dannysmith@users.sourceforge.net>
* 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.
2005-01-06 Danny Smith <dannysmith@users.sourceforge.net>
* include/_mingw.h (__int16): Define as short.
@ -23,7 +36,7 @@
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.
(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):

View File

@ -46,7 +46,6 @@ extern "C" {
#ifndef RC_INVOKED
/* TODO: long double versions */
double __MINGW_ATTRIB_CONST creal (double _Complex);
double __MINGW_ATTRIB_CONST cimag (double _Complex);
double __MINGW_ATTRIB_CONST carg (double _Complex);
@ -93,8 +92,32 @@ float _Complex cpowf (float _Complex, float _Complex);
float _Complex csqrtf (float _Complex);
float _Complex __MINGW_ATTRIB_CONST cprojf (float _Complex);
long double __MINGW_ATTRIB_CONST creall (long double _Complex);
long double __MINGW_ATTRIB_CONST cimagl (long double _Complex);
long double __MINGW_ATTRIB_CONST cargl (long double _Complex);
long double __MINGW_ATTRIB_CONST cabsl (long double _Complex);
long double _Complex __MINGW_ATTRIB_CONST conjl (long double _Complex);
long double _Complex cacosl (long double _Complex);
long double _Complex casinl (long double _Complex);
long double _Complex catanl (long double _Complex);
long double _Complex ccosl (long double _Complex);
long double _Complex csinl (long double _Complex);
long double _Complex ctanl (long double _Complex);
long double _Complex cacoshl (long double _Complex);
long double _Complex casinhl (long double _Complex);
long double _Complex catanhl (long double _Complex);
long double _Complex ccoshl (long double _Complex);
long double _Complex csinhl (long double _Complex);
long double _Complex ctanhl (long double _Complex);
long double _Complex cexpl (long double _Complex);
long double _Complex clogl (long double _Complex);
long double _Complex cpowl (long double _Complex, long double _Complex);
long double _Complex csqrtl (long double _Complex);
long double _Complex __MINGW_ATTRIB_CONST cprojl (long double _Complex);
#ifdef __GNUC__
/* double */
__CRT_INLINE double __MINGW_ATTRIB_CONST creal (double _Complex _Z)
{
return __real__ _Z;
@ -119,6 +142,7 @@ __CRT_INLINE double __MINGW_ATTRIB_CONST carg (double _Complex _Z)
}
/* float */
__CRT_INLINE float __MINGW_ATTRIB_CONST crealf (float _Complex _Z)
{
return __real__ _Z;
@ -141,6 +165,31 @@ __CRT_INLINE float __MINGW_ATTRIB_CONST cargf (float _Complex _Z)
: "=t" (res) : "0" (__real__ _Z), "u" (__imag__ _Z) : "st(1)");
return res;
}
/* long double */
__CRT_INLINE long double __MINGW_ATTRIB_CONST creall (long double _Complex _Z)
{
return __real__ _Z;
}
__CRT_INLINE long double __MINGW_ATTRIB_CONST cimagl (long double _Complex _Z)
{
return __imag__ _Z;
}
__CRT_INLINE long double _Complex __MINGW_ATTRIB_CONST conjl (long double _Complex _Z)
{
return __extension__ ~_Z;
}
__CRT_INLINE long double __MINGW_ATTRIB_CONST cargl (long double _Complex _Z)
{
long double res;
__asm__ ("fpatan;"
: "=t" (res) : "0" (__real__ _Z), "u" (__imag__ _Z) : "st(1)");
return res;
}
#endif /* __GNUC__ */

View File

@ -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) \

View File

@ -0,0 +1,7 @@
#include <math.h>
#include <complex.h>
long double cabsl (long double complex Z)
{
return hypotl ( __real__ Z, __imag__ Z);
}

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,5 @@
#include <complex.h>
long double __attribute__ ((const)) cimagl (long double complex _Z)
{
return __imag__ _Z;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,5 @@
#include <complex.h>
long double __attribute__ ((const)) creall (long double complex _Z)
{
return __real__ _Z;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}