* mingwex/complex/(cabsf.c cacosf.c cacoshf.c cargf.c casinf.c
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.
This commit is contained in:
7
winsup/mingw/mingwex/complex/cabsf.c
Executable file
7
winsup/mingw/mingwex/complex/cabsf.c
Executable file
@@ -0,0 +1,7 @@
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
float cabsf (float complex Z)
|
||||
{
|
||||
return (float) _hypot ( __real__ Z, __imag__ Z);
|
||||
}
|
64
winsup/mingw/mingwex/complex/cacosf.c
Executable file
64
winsup/mingw/mingwex/complex/cacosf.c
Executable file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
cacosf.c
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
#if 0
|
||||
/* cacos (Z) = -I * clog(Z + I * csqrt(1 - Z * Z)) */
|
||||
|
||||
float complex cacos (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
float x, y;
|
||||
|
||||
x = __real__ Z;
|
||||
y = __imag__ Z;
|
||||
|
||||
if (y == 0.0f)
|
||||
{
|
||||
__real__ Res = acosf (x);
|
||||
__imag__ Res = 0.0f;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
float complex ZZ;
|
||||
/* Z * Z = ((x - y) * (x + y)) + (2.0 * x * y) * I */
|
||||
/* caculate 1 - Z * Z */
|
||||
__real__ ZZ = 1.0f - (x - y) * (x + y);
|
||||
__imag__ ZZ = -2.0f * x * y;
|
||||
|
||||
|
||||
Res = csqrtf(ZZ);
|
||||
|
||||
/* calculate ZZ + I * sqrt (ZZ) */
|
||||
|
||||
__real__ ZZ = x - __imag__ Res;
|
||||
__imag__ ZZ = y + __real__ Res;
|
||||
|
||||
ZZ = clog(ZZ);
|
||||
|
||||
/* mult by -I */
|
||||
|
||||
__real__ Res = __imag__ ZZ;
|
||||
__imag__ Res = - __real__ ZZ;
|
||||
}
|
||||
return Res;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* cacos ( Z ) = pi/2 - casin ( Z ) */
|
||||
|
||||
float complex cacosf (float complex Z)
|
||||
{
|
||||
float complex Res = casinf (Z);
|
||||
__real__ Res = M_PI_2 - __real__ Res;
|
||||
__imag__ Res = - __imag__ Res;
|
||||
return Res;
|
||||
}
|
||||
#endif
|
37
winsup/mingw/mingwex/complex/cacoshf.c
Executable file
37
winsup/mingw/mingwex/complex/cacoshf.c
Executable file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
cacoshf.c
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
#if 0
|
||||
/* cacoshf (z) = I * cacos (z) */
|
||||
float complex cacosh (float complex Z)
|
||||
{
|
||||
float complex Tmp;
|
||||
float complex Res;
|
||||
|
||||
Tmp = cacosf (Z);
|
||||
__real__ Res = -__imag__ Tmp;
|
||||
__imag__ Res = __real__ Tmp;
|
||||
return Res;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* cacosh (z) = I * cacos (z) = I * (pi/2 - casin (z)) */
|
||||
|
||||
float complex cacoshf (float complex Z)
|
||||
{
|
||||
float complex Tmp;
|
||||
float complex Res;
|
||||
|
||||
Tmp = casinf (Z);
|
||||
__real__ Res = __imag__ Tmp;
|
||||
__imag__ Res = M_PI_2 - __real__ Tmp;
|
||||
return Res;
|
||||
}
|
||||
#endif
|
9
winsup/mingw/mingwex/complex/cargf.c
Executable file
9
winsup/mingw/mingwex/complex/cargf.c
Executable file
@@ -0,0 +1,9 @@
|
||||
#include <complex.h>
|
||||
float __attribute__ ((const)) cargf (float _Complex _Z)
|
||||
{
|
||||
float res;
|
||||
__asm__ ("fpatan;"
|
||||
: "=t" (res) : "0" (__real__ _Z), "u" (__imag__ _Z) : "st(1)");
|
||||
return res;
|
||||
}
|
||||
|
48
winsup/mingw/mingwex/complex/casinf.c
Executable file
48
winsup/mingw/mingwex/complex/casinf.c
Executable file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
casinf.c
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
/* casin (Z ) = -I * clog(I * Z + csqrt (1.0 - Z * Z))) */
|
||||
|
||||
float complex casinf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
float x, y;
|
||||
|
||||
x = __real__ Z;
|
||||
y = __imag__ Z;
|
||||
|
||||
if (y == 0.0f)
|
||||
{
|
||||
__real__ Res = asinf (x);
|
||||
__imag__ Res = 0.0f;
|
||||
}
|
||||
else /* -I * clog(I * Z + csqrt(1.0 - Z * Z))) */
|
||||
{
|
||||
float complex ZZ;
|
||||
|
||||
/* Z * Z = ((x - y) * (x + y)) + (2.0 * x * y) * I */
|
||||
/* calculate 1 - Z * Z */
|
||||
__real__ ZZ = 1.0f - (x - y) * (x + y);
|
||||
__imag__ ZZ = -2.0f * x * y;
|
||||
ZZ = csqrtf (ZZ);
|
||||
|
||||
|
||||
/* add I * Z to ZZ */
|
||||
|
||||
__real__ ZZ -= y;
|
||||
__imag__ ZZ += x;
|
||||
|
||||
ZZ = clogf (ZZ);
|
||||
|
||||
/* mult by -I */
|
||||
__real__ Res = __imag__ ZZ;
|
||||
__imag__ Res = - __real__ ZZ;
|
||||
}
|
||||
return (Res);
|
||||
}
|
23
winsup/mingw/mingwex/complex/casinhf.c
Executable file
23
winsup/mingw/mingwex/complex/casinhf.c
Executable file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
casinhf.c
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
/* casinh (z) = -I casin (I * z) */
|
||||
|
||||
float complex casinhf (float complex Z)
|
||||
{
|
||||
float complex Tmp;
|
||||
float complex Res;
|
||||
|
||||
__real__ Tmp = - __imag__ Z;
|
||||
__imag__ Tmp = __real__ Z;
|
||||
Tmp = casinf (Tmp);
|
||||
__real__ Res = __imag__ Tmp;
|
||||
__imag__ Res = - __real__ Tmp;
|
||||
return Res;
|
||||
}
|
49
winsup/mingw/mingwex/complex/catanf.c
Executable file
49
winsup/mingw/mingwex/complex/catanf.c
Executable file
@@ -0,0 +1,49 @@
|
||||
/* 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;
|
||||
}
|
23
winsup/mingw/mingwex/complex/catanhf.c
Executable file
23
winsup/mingw/mingwex/complex/catanhf.c
Executable file
@@ -0,0 +1,23 @@
|
||||
/* catanhf.c */
|
||||
/*
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
/* catanh (z) = -I * catan (I * z) */
|
||||
|
||||
float complex catanhf (float complex Z)
|
||||
{
|
||||
float complex Tmp;
|
||||
float complex Res;
|
||||
|
||||
__real__ Tmp = - __imag__ Z;
|
||||
__imag__ Tmp = __real__ Z;
|
||||
Tmp = catanf (Tmp);
|
||||
__real__ Res = __imag__ Tmp;
|
||||
__imag__ Res = - __real__ Tmp;
|
||||
return Res;
|
||||
}
|
20
winsup/mingw/mingwex/complex/ccosf.c
Executable file
20
winsup/mingw/mingwex/complex/ccosf.c
Executable file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
ccosf.c
|
||||
Contributed by Danny Smith
|
||||
2003-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
/* ccos (x + I * y) = cos (x) * cosh (y)
|
||||
+ I * (sin (x) * sinh (y)) */
|
||||
|
||||
|
||||
float complex ccosf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
__real__ Res = cosf (__real__ Z) * coshf ( __imag__ Z);
|
||||
__imag__ Res = -sinf (__real__ Z) * sinhf ( __imag__ Z);
|
||||
return Res;
|
||||
}
|
19
winsup/mingw/mingwex/complex/ccoshf.c
Executable file
19
winsup/mingw/mingwex/complex/ccoshf.c
Executable file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
ccoshf.c
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
/* ccosh (x + I * y) = cosh (x) * cos (y)
|
||||
+ I * (sinh (x) * sin (y)) */
|
||||
|
||||
float complex ccoshf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
__real__ Res = coshf (__real__ Z) * cosf (__imag__ Z);
|
||||
__imag__ Res = sinhf (__real__ Z) * sinf (__imag__ Z);
|
||||
return Res;
|
||||
}
|
19
winsup/mingw/mingwex/complex/cexpf.c
Executable file
19
winsup/mingw/mingwex/complex/cexpf.c
Executable file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
cexpf.c
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
/* cexp (x + I * y) = exp (x) * cos (y) + I * exp (x) * sin (y) */
|
||||
|
||||
float complex cexpf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
double rho = exp (__real__ Z);
|
||||
__real__ Res = rho * cosf(__imag__ Z);
|
||||
__imag__ Res = rho * sinf(__imag__ Z);
|
||||
return Res;
|
||||
}
|
6
winsup/mingw/mingwex/complex/cimagf.c
Executable file
6
winsup/mingw/mingwex/complex/cimagf.c
Executable file
@@ -0,0 +1,6 @@
|
||||
#include <complex.h>
|
||||
float __attribute__ ((const)) cimagf (float complex _Z)
|
||||
{
|
||||
return __imag__ _Z;
|
||||
}
|
||||
|
19
winsup/mingw/mingwex/complex/clogf.c
Executable file
19
winsup/mingw/mingwex/complex/clogf.c
Executable file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
clogf.c
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
/* clog (x + I * y) = log (hypot (x, y)) + I * atan2 (y, x) */
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
float complex clogf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
__real__ Res = logf (_hypot (__real__ Z, __imag__ Z));
|
||||
__imag__ Res = cargf (Z);
|
||||
return Res;
|
||||
}
|
||||
|
43
winsup/mingw/mingwex/complex/cpowf.c
Executable file
43
winsup/mingw/mingwex/complex/cpowf.c
Executable file
@@ -0,0 +1,43 @@
|
||||
/* cpowf.c */
|
||||
/*
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
/* cpow(X, Y) = cexp(X * clog(Y)) */
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
float complex cpowf (float complex X, float complex Y)
|
||||
{
|
||||
float complex Res;
|
||||
float i;
|
||||
float r = _hypot (__real__ X, __imag__ X);
|
||||
if (r == 0.0f)
|
||||
{
|
||||
__real__ Res = __imag__ Res = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
float rho;
|
||||
float theta;
|
||||
i = cargf (X);
|
||||
theta = i * __real__ Y;
|
||||
|
||||
if (__imag__ Y == 0.0f)
|
||||
/* This gives slightly more accurate results in these cases. */
|
||||
rho = powf (r, __real__ Y);
|
||||
else
|
||||
{
|
||||
r = logf (r);
|
||||
/* rearrangement of cexp(X * clog(Y)) */
|
||||
theta += r * __imag__ Y;
|
||||
rho = expf (r * __real__ Y - i * __imag__ Y);
|
||||
}
|
||||
|
||||
__real__ Res = rho * cosf (theta);
|
||||
__imag__ Res = rho * sinf (theta);
|
||||
}
|
||||
return Res;
|
||||
}
|
22
winsup/mingw/mingwex/complex/cprojf.c
Executable file
22
winsup/mingw/mingwex/complex/cprojf.c
Executable file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
cprojf.c
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
/* Return the value of the projection onto the Riemann sphere.*/
|
||||
|
||||
float complex cprojf (float complex Z)
|
||||
{
|
||||
complex float Res = Z;
|
||||
if (isinf (__real__ Z) || isinf (__imag__ Z))
|
||||
{
|
||||
__real__ Res = HUGE_VALF;
|
||||
__imag__ Res = copysignf (0.0f, __imag__ Z);
|
||||
}
|
||||
return Res;
|
||||
}
|
||||
|
6
winsup/mingw/mingwex/complex/crealf.c
Executable file
6
winsup/mingw/mingwex/complex/crealf.c
Executable file
@@ -0,0 +1,6 @@
|
||||
#include <complex.h>
|
||||
float __attribute__ ((const)) crealf (float complex _Z)
|
||||
{
|
||||
return __real__ _Z;
|
||||
}
|
||||
|
21
winsup/mingw/mingwex/complex/csinf.c
Executable file
21
winsup/mingw/mingwex/complex/csinf.c
Executable file
@@ -0,0 +1,21 @@
|
||||
/* csinf.c */
|
||||
|
||||
/*
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
/* csin (x + I * y) = sin (x) * cosh (y)
|
||||
+ I * (cos (x) * sinh (y)) */
|
||||
|
||||
float complex csinf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
__real__ Res = sinf (__real__ Z) * coshf ( __imag__ Z);
|
||||
__imag__ Res = cosf (__real__ Z) * sinhf ( __imag__ Z);
|
||||
return Res;
|
||||
}
|
||||
|
21
winsup/mingw/mingwex/complex/csinhf.c
Executable file
21
winsup/mingw/mingwex/complex/csinhf.c
Executable file
@@ -0,0 +1,21 @@
|
||||
/* csinhf.c */
|
||||
/*
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
/* csinh (x + I * y) = sinh (x) * cos (y)
|
||||
+ I * (cosh (x) * sin (y)) */
|
||||
|
||||
|
||||
float complex csinhf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
__real__ Res = sinhf (__real__ Z) * cosf (__imag__ Z);
|
||||
__imag__ Res = coshf (__real__ Z) * sinf (__imag__ Z);
|
||||
return Res;
|
||||
}
|
49
winsup/mingw/mingwex/complex/csqrtf.c
Executable file
49
winsup/mingw/mingwex/complex/csqrtf.c
Executable file
@@ -0,0 +1,49 @@
|
||||
#include <math.h>
|
||||
#include <complex.h>
|
||||
|
||||
float complex csqrtf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
float r;
|
||||
float x = __real__ Z;
|
||||
float y = __imag__ Z;
|
||||
|
||||
if (y == 0.0f)
|
||||
{
|
||||
if (x < 0.0f)
|
||||
{
|
||||
__real__ Res = 0.0f;
|
||||
__imag__ Res = sqrtf (-x);
|
||||
}
|
||||
else
|
||||
{
|
||||
__real__ Res = sqrtf (x);
|
||||
__imag__ Res = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
else if (x == 0.0f)
|
||||
{
|
||||
r = sqrtf(0.5f * fabsf (y));
|
||||
__real__ Res = y > 0 ? r : -r;
|
||||
__imag__ Res = r;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
float t = sqrtf (2 * (_hypot (__real__ Z, __imag__ Z) + fabsf (x)));
|
||||
float u = t / 2.0f;
|
||||
if ( x > 0.0f)
|
||||
{
|
||||
__real__ Res = u;
|
||||
__imag__ Res = y / t;
|
||||
}
|
||||
else
|
||||
{
|
||||
__real__ Res = fabsf (y / t);
|
||||
__imag__ Res = y < 0 ? -u : u;
|
||||
}
|
||||
}
|
||||
|
||||
return Res;
|
||||
}
|
41
winsup/mingw/mingwex/complex/ctanf.c
Executable file
41
winsup/mingw/mingwex/complex/ctanf.c
Executable file
@@ -0,0 +1,41 @@
|
||||
/* ctanf.c */
|
||||
|
||||
/*
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
#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)) */
|
||||
|
||||
float complex ctanf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
float two_I = 2.0f * __imag__ Z;
|
||||
float two_R = 2.0f * __real__ Z;
|
||||
float denom = cosf (two_R) + coshf (two_I);
|
||||
if (denom == 0.0f)
|
||||
{
|
||||
errno = ERANGE;
|
||||
__real__ Res = HUGE_VALF;
|
||||
__imag__ Res = HUGE_VALF;
|
||||
}
|
||||
else if (isinf (denom))
|
||||
{
|
||||
errno = ERANGE;
|
||||
__real__ Res = 0.0;
|
||||
__imag__ Res = two_I > 0 ? 1.0f : -1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
__real__ Res = sinf (two_R) / denom;
|
||||
__imag__ Res = sinhf (two_I) / denom;
|
||||
}
|
||||
return Res;
|
||||
}
|
||||
|
44
winsup/mingw/mingwex/complex/ctanhf.c
Executable file
44
winsup/mingw/mingwex/complex/ctanhf.c
Executable file
@@ -0,0 +1,44 @@
|
||||
/* ctanhf.c */
|
||||
|
||||
/*
|
||||
Contributed by Danny Smith
|
||||
2004-12-24
|
||||
*/
|
||||
|
||||
|
||||
#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)) .
|
||||
*/
|
||||
|
||||
float complex
|
||||
ctanhf (float complex Z)
|
||||
{
|
||||
float complex Res;
|
||||
float two_R = 2.0f * __real__ Z;
|
||||
float two_I = 2.0f * __imag__ Z;
|
||||
float denom = coshf (two_R) + cosf (two_I);
|
||||
|
||||
if (denom == 0.0f)
|
||||
{
|
||||
errno = ERANGE;
|
||||
__real__ Res = HUGE_VALF;
|
||||
__imag__ Res = HUGE_VALF;
|
||||
}
|
||||
else if (isinf (denom))
|
||||
{
|
||||
errno = ERANGE;
|
||||
__real__ Res = two_R > 0 ? 1.0f : -1.0f;
|
||||
__imag__ Res = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
__real__ Res = sinhf (two_R) / denom;
|
||||
__imag__ Res = sinf (two_I) / denom;
|
||||
}
|
||||
return Res;
|
||||
}
|
Reference in New Issue
Block a user