Mercurial > mxe-octave
diff src/build-msvctools/compat/csqrtf.c @ 3061:f8299bb6c872
Initial support for native MSVC compilation.
* add MSVC support files: compiler wrappers and support libraries
* adapt libiconv to work with MSVC
* adapt gettext to work with MSVC
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Mon, 17 Jun 2013 22:43:11 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/build-msvctools/compat/csqrtf.c Mon Jun 17 22:43:11 2013 -0400 @@ -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 = r; + __imag__ Res = y > 0 ? r : -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; +}