Jspice3
complex.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1985 Thomas L. Quarles
3  */
4 #ifndef CMPLX
5 #define CMPLX "complex.h $Revision: 1.5 $ on $Date: 88/11/22 02:51:07 $ "
6 
7 /* header file containing definitions for complex functions
8  *
9  * Each expects two arguments for each complex number - a real and an
10  * imaginary part.
11  */
12 typedef struct {
13  double real;
14  double imag;
15 } SPcomplex;
16 
17 
18 #define DC_ABS(a,b) (FABS(a) + FABS(b))
19 
20 #ifdef notdef
21 #define DC_DIV(a,b,c,d,x,y) { \
22  double r,s; \
23  if(FABS(c)>FABS(d)) { \
24  r=(d)/(c); \
25  s=(c)+r*(d); \
26  x=((a)+(b)*r)/s; \
27  y=((b)-(a)*r)/s; \
28  } else { \
29  r=(c)/(d); \
30  s=(d)+r*(c); \
31  x=((a)*r+(b))/s; \
32  y=((b)*r-(a))/s; \
33  } \
34 }
35 #endif /*notdef */
36 
37 #ifndef HAVE_SHORTMACRO
38 #define DC_DIVEQ(a,b,c,d) { \
39  double r,s,x,y; \
40  if(FABS(c)>FABS(d)) { \
41  r=(d)/(c); \
42  s=(c)+r*(d); \
43  x=((*(a))+(*(b))*r)/s; \
44  y=((*(b))-(*(a))*r)/s; \
45  } else { \
46  r=(c)/(d); \
47  s=(d)+r*(c); \
48  x=((*(a))*r+(*(b)))/s; \
49  y=((*(b))*r-(*(a)))/s; \
50  } \
51  (*(a)) = x; \
52  (*(b)) = y; \
53 }
54 #else /* HAVE_SHORTMACRO */
55 #define DC_DIVEQ DCdiveq
56 #ifdef __STDC__
57 extern void DCdiveq(double*,double*,double,double);
58 #else /* stdc */
59 extern void DCdiveq();
60 #endif /* stdc */
61 #endif /* HAVE_SHORTMACRO */
62 
63 #ifndef HAVE_SHORTMACRO
64 #define DC_MULT(a,b,c,d,x,y) { \
65  *(x) = (a) * (c) - (b) * (d) ; \
66  *(y) = (a) * (d) + (b) * (c) ; \
67 }
68 #else /* HAVE_SHORTMACRO */
69 #define DC_MULT DCmult
70 #ifdef __STDC__
71 extern void DCmult(double,double,double,double,double*,double*);
72 #else /* stdc */
73 extern void DCmult();
74 #endif /* stdc */
75 #endif /* HAVE_SHORTMACRO */
76 
77 #ifdef notdef
78 #define DC_MINUS(a,b,c,d,x,y) { \
79  (x) = (a) - (c) ; \
80  (y) = (b) - (d) ; \
81 }
82 #endif /* notdef */
83 
84 #ifndef HAVE_SHORTMACRO
85 #define DC_MINUSEQ(a,b,c,d) { \
86  *(a) -= (c) ; \
87  *(b) -= (d) ; \
88 }
89 #else /* HAVE_SHORTMACRO */
90 #define DC_MINUSEQ DCminusEq
91 #ifdef __STDC__
92 extern void DCminusEq(double*,double*,double,double);
93 #else /* stdc */
94 extern void DCminusEq();
95 #endif /* stdc */
96 #endif /* HAVE_SHORTMACRO */
97 
98 #define C_SQRT(A) { \
99  double _mag, _a; \
100  if ((A).imag == 0.0) { \
101  if ((A).real < 0.0) { \
102  (A).imag = sqrt(-(A).real); \
103  (A).real = 0.0; \
104  } else { \
105  (A).real = sqrt((A).real); \
106  (A).imag = 0.0; \
107  } \
108  } else { \
109  _mag = sqrt((A).real * (A).real + (A).imag * (A).imag); \
110  _a = (_mag - (A).real) / 2.0; \
111  if (_a <= 0.0) { \
112  (A).real = sqrt(_mag); \
113  (A).imag /= (2.0 * (A).real); /*XXX*/ \
114  } else { \
115  _a = sqrt(_a); \
116  (A).real = (A).imag / (2.0 * _a); \
117  (A).imag = _a; \
118  } \
119  } \
120 }
121 
122 #define C_MAG2(A) (((A).real = (A).real * (A).real + (A).imag * (A).imag), \
123  (A).imag = 0.0)
124 
125 #define C_CONJ(A) ((A).imag *= -1.0)
126 
127 #define C_CONJEQ(A,B) { \
128  (A).real = (B.real); \
129  (A).imag = - (B.imag); \
130 }
131 
132 #define C_EQ(A,B) { \
133  (A).real = (B.real); \
134  (A).imag = (B.imag); \
135 }
136 
137 #define C_NORM(A,B) { \
138  if ((A).real == 0.0 && (A).imag == 0.0) { \
139  (B) = 0; \
140  } else { \
141  while (FABS((A).real) > 1.0 || FABS((A).imag) > 1.0) { \
142  (B) += 1; \
143  (A).real /= 2.0; \
144  (A).imag /= 2.0; \
145  } \
146  while (FABS((A).real) <= 0.5 && FABS((A).imag) <= 0.5) { \
147  (B) -= 1; \
148  (A).real *= 2.0; \
149  (A).imag *= 2.0; \
150  } \
151  } \
152 }
153 
154 #define C_ABS(A) (sqrt((A).real * (A.real) + (A.imag * A.imag)))
155 
156 #define C_MUL(A,B) { \
157  double TMP1, TMP2; \
158  TMP1 = (A.real); \
159  TMP2 = (B.real); \
160  (A).real = TMP1 * TMP2 - (A.imag) * (B.imag); \
161  (A).imag = TMP1 * (B.imag) + (A.imag) * TMP2; \
162 }
163 
164 #define C_MULEQ(A,B,C) { \
165  (A).real = (B.real) * (C.real) - (B.imag) * (C.imag); \
166  (A).imag = (B.real) * (C.imag) + (B.imag) * (C.real); \
167 }
168 
169 #define C_DIV(A,B) { \
170  double _tmp, _mag; \
171  _tmp = (A.real); \
172  (A).real = _tmp * (B.real) + (A).imag * (B.imag); \
173  (A).imag = - _tmp * (B.imag) + (A.imag) * (B.real); \
174  _mag = (B.real) * (B.real) + (B.imag) * (B.imag); \
175  (A).real /= _mag; \
176  (A).imag /= _mag; \
177 }
178 
179 #define C_DIVEQ(A,B,C) { \
180  double _mag; \
181  (A).real = (B.real) * (C.real) + (B.imag) * (C.imag); \
182  (A).imag = (B.imag) * (C.real) - (B.real) * (C.imag); \
183  _mag = (C.real) * (C.real) + (C.imag) * (C.imag); \
184  (A).real /= _mag; \
185  (A).imag /= _mag; \
186 }
187 
188 #define C_ADD(A,B) { \
189  (A).real += (B.real); \
190  (A).imag += (B.imag); \
191 }
192 
193 #define C_ADDEQ(A,B,C) { \
194  (A).real = (B.real) + (C.real); \
195  (A).imag = (B.imag) + (C.imag); \
196 }
197 
198 #define C_SUB(A,B) { \
199  (A).real -= (B.real); \
200  (A).imag -= (B.imag); \
201 }
202 
203 #define C_SUBEQ(A,B,C) { \
204  (A).real = (B.real) - (C.real); \
205  (A).imag = (B.imag) - (C.imag); \
206 }
207 
208 #endif /*CMPLX*/
double real
Definition: complex.h:13
double imag
Definition: complex.h:14