25 #ifndef _COMPLEX_ARITH_H_
26 #define _COMPLEX_ARITH_H_
38 #define complex _complex_type
41 __attribute__((pure,unused))
53 __attribute__((pure,unused))
60 result.imag = -z.imag;
65 __attribute__((pure,unused))
71 result.real = w.real + z.real;
72 result.imag = w.imag + z.imag;
77 __attribute__((pure,unused))
83 result.real = -z.real;
84 result.imag = -z.imag;
89 __attribute__((pure,unused))
95 result.real = w.real - z.real;
96 result.imag = w.imag - z.imag;
101 __attribute__((pure,unused))
107 result.real = w.real * z.real - w.imag * z.imag;
108 result.imag = w.real * z.imag + w.imag * z.real;
113 __attribute__((pure,unused))
123 if (fabs(z.real) >= fabs(z.imag))
125 double ratio = z.imag / z.real;
126 double denom = z.real + z.imag * ratio;
127 result.real = 1 / denom;
128 result.imag = -ratio / denom;
132 double ratio = z.real / z.imag;
133 double denom = z.real * ratio + z.imag;
134 result.real = ratio / denom;
135 result.imag = -1 / denom;
142 __attribute__((pure,unused))
150 if (fabs(z.real) >= fabs(z.imag))
152 double ratio = z.imag / z.real;
153 double denom = z.real + z.imag * ratio;
154 result.real = (w.real + w.imag * ratio) / denom;
155 result.imag = (w.imag - w.real * ratio) / denom;
159 double ratio = z.real / z.imag;
160 double denom = z.real * ratio + z.imag;
161 result.real = (w.real * ratio + w.imag) / denom;
162 result.imag = (w.imag * ratio - w.real) / denom;
169 __attribute__((pure,unused))
174 z.real = fabs(z.real);
175 z.imag = fabs(z.imag);
178 if (z.real >= z.imag)
180 double ratio = z.imag / z.real;
181 return z.real * sqrt(1.0 + ratio * ratio);
185 double ratio = z.real / z.imag;
186 return z.imag * sqrt(1.0 + ratio * ratio);
191 __attribute__((pure,unused))
196 return atan2(z.imag, z.real);
200 __attribute__((pure,unused))
206 double mag_w =
c_mag(w);
207 double arg_w =
c_arg(w);
208 double mag = pow(mag_w, z.real) * exp(-z.imag * arg_w);
209 double arg = z.real * arg_w + z.imag * log(mag_w);
210 result.real = mag * cos(arg);
211 result.imag = mag * sin(arg);
216 __attribute__((pure,unused))
222 double mag = pow(
c_mag(w), x);
223 double arg =
c_arg(w) * x;
224 result.real = mag * cos(arg);
225 result.imag = mag * sin(arg);
230 __attribute__((pure,unused))
237 result.real = sqrt((r + z.real) / 2);
238 result.imag = sqrt((r - z.real) / 2);
241 result.imag = -result.imag;
247 __attribute__((pure,unused))
252 double r = exp(z.real);
254 result.real = r * cos(z.imag);
255 result.imag = r * sin(z.imag);
260 __attribute__((pure,unused))
266 result.real = log(
c_mag(z));
267 result.imag =
c_arg(z);