diff options
author | Danny Smith <dannysmith@users.sourceforge.net> | 2004-12-25 23:56:19 +0000 |
---|---|---|
committer | Danny Smith <dannysmith@users.sourceforge.net> | 2004-12-25 23:56:19 +0000 |
commit | 9a3412eea8a2aa2daafa031f2e94f7049c1de202 (patch) | |
tree | 1552eee2b8273a45c572c248f5fdd6ef93185850 /winsup/mingw/mingwex/complex/cpowf.c | |
parent | c98b30eadcd911512c4d48f8c529c499724a0161 (diff) | |
download | cygnal-9a3412eea8a2aa2daafa031f2e94f7049c1de202.tar.gz cygnal-9a3412eea8a2aa2daafa031f2e94f7049c1de202.tar.bz2 cygnal-9a3412eea8a2aa2daafa031f2e94f7049c1de202.zip |
* 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.
Diffstat (limited to 'winsup/mingw/mingwex/complex/cpowf.c')
-rwxr-xr-x | winsup/mingw/mingwex/complex/cpowf.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/winsup/mingw/mingwex/complex/cpowf.c b/winsup/mingw/mingwex/complex/cpowf.c new file mode 100755 index 000000000..eeeed1b7f --- /dev/null +++ b/winsup/mingw/mingwex/complex/cpowf.c @@ -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; +} |