OSDN Git Service

eb2a388fced904badb81c3aadb642e5ef1eb710a
[mingw/mingw-org-wsl.git] / mingwrt / mingwex / complex / csqrtf.c
1 #include <math.h>
2 #include <complex.h>
3
4 float complex  csqrtf (float complex Z)
5 {
6   float complex Res;
7   float r;
8   float x = __real__ Z;
9   float y = __imag__ Z;
10
11   if (y == 0.0f)
12     {
13       if (x < 0.0f)
14         {
15           __real__ Res = 0.0f;
16           __imag__ Res = sqrtf (-x);
17         }
18       else
19         {
20           __real__ Res = sqrtf (x);
21           __imag__ Res = 0.0f;
22         }
23     }
24
25   else if (x == 0.0f)
26     {
27       r = sqrtf(0.5f * fabsf (y));
28       __real__ Res = r;
29       __imag__ Res = y > 0 ? r : -r;
30     }
31
32   else
33     {
34       float t = sqrtf (2 * (_hypot (__real__ Z, __imag__ Z) + fabsf (x)));
35       float u = t / 2.0f;
36       if ( x > 0.0f)
37         {
38           __real__ Res = u;
39           __imag__ Res = y / t;
40         }
41       else
42         {
43           __real__ Res = fabsf (y / t);
44           __imag__ Res = y < 0 ? -u : u;
45         }
46     }
47
48   return Res;
49 }