2 * Placed into the public domain.
3 * Written by Walter Bright
10 typedef struct Complex
16 Complex _complex_div(Complex x, Complex y)
22 if (fabs(y.re) < fabs(y.im))
25 den = y.im + r * y.re;
26 q.re = (x.re * r + x.im) / den;
27 q.im = (x.im * r - x.re) / den;
32 den = y.re + r * y.im;
33 q.re = (x.re + r * x.im) / den;
34 q.im = (x.im - r * x.re) / den;
39 Complex _complex_mul(Complex x, Complex y)
43 p.re = x.re * y.re - x.im * y.im;
44 p.im = x.im * y.re + x.re * y.im;
48 long double _complex_abs(Complex z)
50 long double x,y,ans,temp;
61 ans = x * sqrt(1 + temp * temp);
66 ans = y * sqrt(1 + temp * temp);
71 Complex _complex_sqrt(Complex z)
76 if (z.re == 0 && z.im == 0)
88 w = sqrt(x) * sqrt(0.5 * (1 + sqrt(1 + r * r)));
93 w = sqrt(y) * sqrt(0.5 * (r + sqrt(1 + r * r)));
98 c.im = z.im / (w + w);
102 c.im = (z.im >= 0) ? w : -w;
103 c.re = z.im / (c.im + c.im);