C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
lx_complex.inl
1 /*
2 ** CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
3 **
4 ** Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
5 ** Universitaet Karlsruhe, Germany
6 ** (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
7 ** Universitaet Wuppertal, Germany
8 **
9 ** This library is free software; you can redistribute it and/or
10 ** modify it under the terms of the GNU Library General Public
11 ** License as published by the Free Software Foundation; either
12 ** version 2 of the License, or (at your option) any later version.
13 **
14 ** This library is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ** Library General Public License for more details.
18 **
19 ** You should have received a copy of the GNU Library General Public
20 ** License along with this library; if not, write to the Free
21 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 
24 /* CVS $Id: lx_complex.inl,v 1.8 2014/01/30 17:23:47 cxsc Exp $ */
25 
26 /*
27 ** F. Blomquist, University of Wuppertal, 19.09.2007;
28 */
29 
30 namespace cxsc {
31 // --------------------------------------------------------------------------
32 // ------- Inline functions and operators related to type lx_complex --------
33 // --------------------------------------------------------------------------
34 
35 inline lx_real Re(const lx_complex &a)
36 { return a.re; }
37 
38 inline lx_real Im(const lx_complex &a)
39 { return a.im; }
40 
41 inline int StagPrec(const lx_complex &a) throw()
42 { return StagPrec(a.re); }
43 
44 inline real expoRe(const lx_complex &a) throw()
45 { return expo(a.re); }
46 
47 inline real expoIm(const lx_complex &a) throw()
48 { return expo(a.im); }
49 
50 inline l_real lr_partRe(const lx_complex &a) throw()
51 { return lr_part(a.re); }
52 
53 inline l_real lr_partIm(const lx_complex &a) throw()
54 { return lr_part(a.im); }
55 
56 inline lx_complex & SetRe(lx_complex &a, const lx_real &b)
57 { a.re = b; return a; } // The real part of a is substituted by b.
58 inline lx_complex & SetRe(lx_complex &a, const l_real &b)
59 { a.re = b; return a; } // The real part of a is substituted by b.
60 inline lx_complex & SetRe(lx_complex &a, const real &b)
61 { a.re = b; return a; } // The real part of a is substituted by b.
62 
63 inline lx_complex & SetIm(lx_complex &a, const lx_real &b)
64 { a.im = b; return a; } // The imaginary part of a is substituted by b.
65 inline lx_complex & SetIm(lx_complex &a, const l_real &b)
66 { a.im = b; return a; } // The imaginary part of a is substituted by b.
67 inline lx_complex & SetIm(lx_complex &a, const real &b)
68 { a.im = b; return a; } // The imaginary part of a is substituted by b.
69 
70 inline lx_complex conj(const lx_complex& a) throw()
71 { return lx_complex(a.re, -a.im); }
72 
73 inline bool operator ! (const lx_complex& a) throw()
74 { return !a.re && !a.im; }
75 
76 inline bool operator == (const lx_complex &a, const lx_complex &b)
77  throw() { return (a.re == b.re && a.im == b.im); }
78 
79 inline bool operator == (const lx_complex &a, const l_complex &b)
80  throw() { return (a.re == Re(b) && a.im == Im(b)); }
81 inline bool operator == (const lx_complex &a, const complex &b)
82  throw() { return (a.re == Re(b) && a.im == Im(b)); }
83 inline bool operator == (const l_complex &a, const lx_complex &b)
84  throw() { return b == a; }
85 inline bool operator == (const complex &a, const lx_complex &b)
86  throw() { return (b == a); }
87 
88 inline bool operator == (const lx_complex &a, const lx_real &b) throw()
89 { return a.re == b && a.im == 0.0; }
90 inline bool operator == (const lx_complex &a, const l_real &b) throw()
91 { return a.re == b && a.im == 0.0; }
92 inline bool operator == (const lx_complex &a, const real &b) throw()
93 { return a.re == b && a.im == 0.0; }
94 
95 inline bool operator == (const lx_real &a, const lx_complex &b) throw()
96 { return a == b.re && b.im == 0.0; }
97 inline bool operator == (const l_real &a, const lx_complex &b) throw()
98 { return a == b.re && b.im == 0.0; }
99 inline bool operator == (const real &a, const lx_complex &b) throw()
100 { return a == b.re && b.im == 0.0; }
101 
102 inline bool operator != (const lx_complex &a, const lx_complex &b) throw()
103 { return !(a == b); }
104 
105 inline bool operator != (const lx_complex &a, const l_complex &b) throw()
106 { return !(a == b); }
107 inline bool operator != (const lx_complex &a, const complex &b) throw()
108 { return !(a == b); }
109 inline bool operator != (const l_complex &a, const lx_complex &b) throw()
110 { return !(a == b); }
111 inline bool operator != (const complex &a, const lx_complex &b) throw()
112 { return !(a == b); }
113 
114 inline bool operator != (const lx_complex &a, const lx_real &b) throw()
115 { return !(a == b); }
116 inline bool operator != (const lx_complex &a, const l_real &b) throw()
117 { return !(a == b); }
118 inline bool operator != (const lx_complex &a, const real &b) throw()
119 { return !(a == b); }
120 inline bool operator != (const lx_real &a, const lx_complex &b) throw()
121 { return !(a == b); }
122 inline bool operator != (const l_real &a, const lx_complex &b) throw()
123 { return !(a == b); }
124 inline bool operator != (const real &a, const lx_complex &b) throw()
125 { return !(a == b); }
126 
127 inline lx_complex operator + (const lx_complex &a) throw()
128 { return a; }
129 inline lx_complex operator - (const lx_complex &a) throw()
130 { return lx_complex(-a.re,-a.im); }
131 
132 inline lx_complex operator + (const lx_complex& a, const lx_complex& b) throw()
133 { return lx_complex(a.re+b.re,a.im+b.im); }
134 
135 inline lx_complex operator + (const lx_complex& a, const l_complex& b) throw()
136 { return a + lx_complex(b); }
137 inline lx_complex operator + (const lx_complex& a, const complex& b) throw()
138 { return a + lx_complex(b); }
139 inline lx_complex operator + (const l_complex& a, const lx_complex& b) throw()
140 { return lx_complex(a) + b; }
141 inline lx_complex operator + (const complex& a, const lx_complex& b) throw()
142 { return lx_complex(a) + b; }
143 inline lx_complex operator + (const lx_complex& a, const lx_real& b) throw()
144 { return lx_complex(a.re + b, Im(a)); }
145 inline lx_complex operator + (const lx_real& a, const lx_complex& b) throw()
146 { return lx_complex(b.re + a, Im(b)); }
147 inline lx_complex operator + (const lx_complex& a, const l_real& b) throw()
148 { return lx_complex(a.re + b, Im(a)); }
149 inline lx_complex operator + (const l_real& a, const lx_complex& b) throw()
150 { return lx_complex(b.re + a, Im(b)); }
151 inline lx_complex operator + (const lx_complex& a, const real& b) throw()
152 { return lx_complex(a.re + b, Im(a)); }
153 inline lx_complex operator + (const real& a, const lx_complex& b) throw()
154 { return lx_complex(b.re + a, Im(b)); }
155 
156 inline lx_complex & operator +=(lx_complex& a, const lx_complex& b) throw()
157 { return a = a+b; }
158 inline lx_complex & operator +=(lx_complex& a, const l_complex& b) throw()
159 { return a = a+b; }
160 inline lx_complex & operator +=(lx_complex& a, const complex& b) throw()
161 { return a = a+b; }
162 inline lx_complex & operator +=(lx_complex& a, const lx_real& b) throw()
163 { return a = a+b; }
164 inline lx_complex & operator +=(lx_complex& a, const l_real& b) throw()
165 { return a = a+b; }
166 inline lx_complex & operator +=(lx_complex& a, const real& b) throw()
167 { return a = a+b; }
168 
169 inline lx_complex operator - (const lx_complex& a, const lx_complex& b) throw()
170 { return a + (-b); }
171 inline lx_complex operator - (const lx_complex& a, const l_complex& b) throw()
172 { return a + (-b); }
173 inline lx_complex operator - (const lx_complex& a, const complex& b) throw()
174 { return a + (-b); }
175 inline lx_complex operator - (const l_complex& a, const lx_complex& b) throw()
176 { return a + (-b); }
177 inline lx_complex operator - (const complex& a, const lx_complex& b) throw()
178 { return a + (-b); }
179 inline lx_complex operator - (const lx_complex& a, const lx_real& b) throw()
180 { return a + (-b); }
181 inline lx_complex operator - (const lx_complex& a, const l_real& b) throw()
182 { return a + (-b); }
183 inline lx_complex operator - (const lx_complex& a, const real& b) throw()
184 { return a + (-b); }
185 inline lx_complex operator - (const lx_real& a, const lx_complex& b) throw()
186 { return a + (-b); }
187 inline lx_complex operator - (const l_real& a, const lx_complex& b) throw()
188 { return a + (-b); }
189 inline lx_complex operator - (const real& a, const lx_complex& b) throw()
190 { return a + (-b); }
191 
192 inline lx_complex & operator -=(lx_complex& a, const lx_complex& b) throw()
193 { return a = a-b; }
194 inline lx_complex & operator -=(lx_complex& a, const l_complex& b) throw()
195 { return a = a-b; }
196 inline lx_complex & operator -=(lx_complex& a, const complex& b) throw()
197 { return a = a-b; }
198 inline lx_complex & operator -=(lx_complex& a, const lx_real& b) throw()
199 { return a = a-b; }
200 inline lx_complex & operator -=(lx_complex& a, const l_real& b) throw()
201 { return a = a-b; }
202 inline lx_complex & operator -=(lx_complex& a, const real& b) throw()
203 { return a = a-b; }
204 
205 
206 inline lx_complex operator * (const lx_complex& a, const lx_complex& b) throw()
207 {
208  lx_real x,y;
209 
210  x = a.re*b.re - a.im*b.im;
211  y = a.im*b.re + a.re*b.im;
212 
213  return lx_complex(x,y);
214 }
215 inline lx_complex operator * (const lx_complex& a, const l_complex& b) throw()
216 { return a*lx_complex(b); }
217 inline lx_complex operator * (const lx_complex& a, const complex& b) throw()
218 { return a*lx_complex(b); }
219 inline lx_complex operator * (const l_complex& a, const lx_complex& b) throw()
220 { return lx_complex(a)*b; }
221 inline lx_complex operator * (const complex& a, const lx_complex& b) throw()
222 { return lx_complex(a)*b; }
223 inline lx_complex operator * (const lx_complex& a, const lx_real& b) throw()
224 { return a*lx_complex(b); }
225 inline lx_complex operator * (const lx_complex& a, const l_real& b) throw()
226 { return a*lx_complex(b); }
227 inline lx_complex operator * (const lx_complex& a, const real& b) throw()
228 { return a*lx_complex(b); }
229 inline lx_complex operator * (const lx_real& a, const lx_complex& b) throw()
230 { return lx_complex(a)*b; }
231 inline lx_complex operator * (const l_real& a, const lx_complex& b) throw()
232 { return lx_complex(a)*b; }
233 inline lx_complex operator * (const real& a, const lx_complex& b) throw()
234 { return lx_complex(a)*b; }
235 
236 inline lx_complex & operator *=(lx_complex& a, const lx_complex& b) throw()
237 { return a = a*b; }
238 inline lx_complex & operator *=(lx_complex& a, const l_complex& b) throw()
239 { return a = a*b; }
240 inline lx_complex & operator *=(lx_complex& a, const complex& b) throw()
241 { return a = a*b; }
242 inline lx_complex & operator *=(lx_complex& a, const lx_real& b) throw()
243 { return a = a*b; }
244 inline lx_complex & operator *=(lx_complex& a, const l_real& b) throw()
245 { return a = a*b; }
246 inline lx_complex & operator *=(lx_complex& a, const real& b) throw()
247 { return a = a*b; }
248 
249 
250 inline lx_complex operator / (const lx_complex& a, const lx_complex& b) throw()
251 {
252  lx_real x,y,Ne;
253 
254  Ne = b.re*b.re + b.im*b.im;
255  x = (a.re*b.re + a.im*b.im) / Ne;
256  y = (a.im*b.re - a.re*b.im) / Ne;
257  return lx_complex(x,y);
258 }
259 inline lx_complex operator / (const lx_complex& a, const l_complex& b) throw()
260 { return a/lx_complex(b); }
261 inline lx_complex operator / (const lx_complex& a, const complex& b) throw()
262 { return a/lx_complex(b); }
263 inline lx_complex operator / (const l_complex& a, const lx_complex& b) throw()
264 { return lx_complex(a)/b; }
265 inline lx_complex operator / (const complex& a, const lx_complex& b) throw()
266 { return lx_complex(a)/b; }
267 inline lx_complex operator / (const lx_complex& a, const lx_real& b) throw()
268 { return a/lx_complex(b); }
269 inline lx_complex operator / (const lx_complex& a, const l_real& b) throw()
270 { return a/lx_complex(b); }
271 inline lx_complex operator / (const lx_complex& a, const real& b) throw()
272 { return a/lx_complex(b); }
273 inline lx_complex operator / (const lx_real& a, const lx_complex& b) throw()
274 { return lx_complex(a)/b; }
275 inline lx_complex operator / (const l_real& a, const lx_complex& b) throw()
276 { return lx_complex(a)/b; }
277 inline lx_complex operator / (const real& a, const lx_complex& b) throw()
278 { return lx_complex(a)/b; }
279 
280 inline lx_complex & operator /=(lx_complex& a, const lx_complex& b) throw()
281 { return a = a/b; }
282 inline lx_complex & operator /=(lx_complex& a, const l_complex& b) throw()
283 { return a = a/b; }
284 inline lx_complex & operator /=(lx_complex& a, const complex& b) throw()
285 { return a = a/b; }
286 inline lx_complex & operator /=(lx_complex& a, const lx_real& b) throw()
287 { return a = a/b; }
288 inline lx_complex & operator /=(lx_complex& a, const l_real& b) throw()
289 { return a = a/b; }
290 inline lx_complex & operator /=(lx_complex& a, const real& b) throw()
291 { return a = a/b; }
292 
293 // --------------------------- Output ---------------------------------
294 
295 inline std::ostream& operator << (std::ostream& s, const lx_complex& a)
296  throw()
297 // A value a of type lx_complex is written to the output channel.
298 // The output has the form: { ? , ? }
299 {
300  s << '('
301  << a.re
302  << " , "
303  << a.im
304  << ')';
305  return s;
306 }
307 
308 inline std::string & operator << (std::string &s, const lx_complex& a) throw()
309 // The value of a variable a of type lx_complex is copied to a string s.
310 // s has the form: ({2**(...)*...} , {2**(...)*...})
311 {
312  string str;
313  s += "(";
314  str = "";
315  str << a.re;
316  s += str;
317  s += " , ";
318  str = "";
319  str << a.im;
320  s += str;
321  s += ")";
322  return s;
323 }
324 
325 } // end namespace cxsc
cimatrix & operator/=(cimatrix &m, const cinterval &c)
Implementation of division and allocation operation.
Definition: cimatrix.inl:1623
The Multiple-Precision Data Type l_real.
Definition: l_real.hpp:77
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition: cdot.cpp:29
civector operator*(const cimatrix_subv &rv, const cinterval &s)
Implementation of multiplication operation.
Definition: cimatrix.inl:731
The Multiple-Precision Data Type l_complex.
Definition: l_complex.hpp:45
The Scalar Type complex.
Definition: complex.hpp:49
cdotprecision & operator+=(cdotprecision &cd, const l_complex &lc)
Implementation of standard algebraic addition and allocation operation.
Definition: cdot.inl:251
civector operator/(const cimatrix_subv &rv, const cinterval &s)
Implementation of division operation.
Definition: cimatrix.inl:730
cimatrix & operator*=(cimatrix &m, const cinterval &c)
Implementation of multiplication and allocation operation.
Definition: cimatrix.inl:1605
The Scalar Type real.
Definition: real.hpp:113