2003-05-15 Eric Christopher <echristo@redhat.com>
[official-gcc.git] / libf2c / libF77 / c_sqrt.c
blob81b72fc372e1dc89cb15483e77ada1c079b0f78c
1 #include "f2c.h"
3 #undef abs
4 #include "math.h"
5 extern double f__cabs (double, double);
7 void
8 c_sqrt (complex * r, complex * z)
10 double mag, t;
11 double zi = z->i, zr = z->r;
13 if ((mag = f__cabs (zr, zi)) == 0.)
14 r->r = r->i = 0.;
15 else if (zr > 0)
17 r->r = t = sqrt (0.5 * (mag + zr));
18 t = zi / t;
19 r->i = 0.5 * t;
21 else
23 t = sqrt (0.5 * (mag - zr));
24 if (zi < 0)
25 t = -t;
26 r->i = t;
27 t = zi / t;
28 r->r = 0.5 * t;