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) noexcept
42 { return StagPrec(a.re); }
43 
44 inline real expoRe(const lx_complex &a) noexcept
45 { return expo(a.re); }
46 
47 inline real expoIm(const lx_complex &a) noexcept
48 { return expo(a.im); }
49 
50 inline l_real lr_partRe(const lx_complex &a) noexcept
51 { return lr_part(a.re); }
52 
53 inline l_real lr_partIm(const lx_complex &a) noexcept
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) noexcept
71 { return lx_complex(a.re, -a.im); }
72 
73 inline bool operator ! (const lx_complex& a) noexcept
74 { return !a.re && !a.im; }
75 
76 inline bool operator == (const lx_complex &a, const lx_complex &b)
77  noexcept { return (a.re == b.re && a.im == b.im); }
78 
79 inline bool operator == (const lx_complex &a, const l_complex &b)
80  noexcept { return (a.re == Re(b) && a.im == Im(b)); }
81 inline bool operator == (const lx_complex &a, const complex &b)
82  noexcept { return (a.re == Re(b) && a.im == Im(b)); }
83 inline bool operator == (const l_complex &a, const lx_complex &b)
84  noexcept { return b == a; }
85 inline bool operator == (const complex &a, const lx_complex &b)
86  noexcept { return (b == a); }
87 
88 inline bool operator == (const lx_complex &a, const lx_real &b) noexcept
89 { return a.re == b && a.im == 0.0; }
90 inline bool operator == (const lx_complex &a, const l_real &b) noexcept
91 { return a.re == b && a.im == 0.0; }
92 inline bool operator == (const lx_complex &a, const real &b) noexcept
93 { return a.re == b && a.im == 0.0; }
94 
95 inline bool operator == (const lx_real &a, const lx_complex &b) noexcept
96 { return a == b.re && b.im == 0.0; }
97 inline bool operator == (const l_real &a, const lx_complex &b) noexcept
98 { return a == b.re && b.im == 0.0; }
99 inline bool operator == (const real &a, const lx_complex &b) noexcept
100 { return a == b.re && b.im == 0.0; }
101 
102 inline bool operator != (const lx_complex &a, const lx_complex &b) noexcept
103 { return !(a == b); }
104 
105 inline bool operator != (const lx_complex &a, const l_complex &b) noexcept
106 { return !(a == b); }
107 inline bool operator != (const lx_complex &a, const complex &b) noexcept
108 { return !(a == b); }
109 inline bool operator != (const l_complex &a, const lx_complex &b) noexcept
110 { return !(a == b); }
111 inline bool operator != (const complex &a, const lx_complex &b) noexcept
112 { return !(a == b); }
113 
114 inline bool operator != (const lx_complex &a, const lx_real &b) noexcept
115 { return !(a == b); }
116 inline bool operator != (const lx_complex &a, const l_real &b) noexcept
117 { return !(a == b); }
118 inline bool operator != (const lx_complex &a, const real &b) noexcept
119 { return !(a == b); }
120 inline bool operator != (const lx_real &a, const lx_complex &b) noexcept
121 { return !(a == b); }
122 inline bool operator != (const l_real &a, const lx_complex &b) noexcept
123 { return !(a == b); }
124 inline bool operator != (const real &a, const lx_complex &b) noexcept
125 { return !(a == b); }
126 
127 inline lx_complex operator + (const lx_complex &a) noexcept
128 { return a; }
129 inline lx_complex operator - (const lx_complex &a) noexcept
130 { return lx_complex(-a.re,-a.im); }
131 
132 inline lx_complex operator + (const lx_complex& a, const lx_complex& b) noexcept
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) noexcept
136 { return a + lx_complex(b); }
137 inline lx_complex operator + (const lx_complex& a, const complex& b) noexcept
138 { return a + lx_complex(b); }
139 inline lx_complex operator + (const l_complex& a, const lx_complex& b) noexcept
140 { return lx_complex(a) + b; }
141 inline lx_complex operator + (const complex& a, const lx_complex& b) noexcept
142 { return lx_complex(a) + b; }
143 inline lx_complex operator + (const lx_complex& a, const lx_real& b) noexcept
144 { return lx_complex(a.re + b, Im(a)); }
145 inline lx_complex operator + (const lx_real& a, const lx_complex& b) noexcept
146 { return lx_complex(b.re + a, Im(b)); }
147 inline lx_complex operator + (const lx_complex& a, const l_real& b) noexcept
148 { return lx_complex(a.re + b, Im(a)); }
149 inline lx_complex operator + (const l_real& a, const lx_complex& b) noexcept
150 { return lx_complex(b.re + a, Im(b)); }
151 inline lx_complex operator + (const lx_complex& a, const real& b) noexcept
152 { return lx_complex(a.re + b, Im(a)); }
153 inline lx_complex operator + (const real& a, const lx_complex& b) noexcept
154 { return lx_complex(b.re + a, Im(b)); }
155 
156 inline lx_complex & operator +=(lx_complex& a, const lx_complex& b) noexcept
157 { return a = a+b; }
158 inline lx_complex & operator +=(lx_complex& a, const l_complex& b) noexcept
159 { return a = a+b; }
160 inline lx_complex & operator +=(lx_complex& a, const complex& b) noexcept
161 { return a = a+b; }
162 inline lx_complex & operator +=(lx_complex& a, const lx_real& b) noexcept
163 { return a = a+b; }
164 inline lx_complex & operator +=(lx_complex& a, const l_real& b) noexcept
165 { return a = a+b; }
166 inline lx_complex & operator +=(lx_complex& a, const real& b) noexcept
167 { return a = a+b; }
168 
169 inline lx_complex operator - (const lx_complex& a, const lx_complex& b) noexcept
170 { return a + (-b); }
171 inline lx_complex operator - (const lx_complex& a, const l_complex& b) noexcept
172 { return a + (-b); }
173 inline lx_complex operator - (const lx_complex& a, const complex& b) noexcept
174 { return a + (-b); }
175 inline lx_complex operator - (const l_complex& a, const lx_complex& b) noexcept
176 { return a + (-b); }
177 inline lx_complex operator - (const complex& a, const lx_complex& b) noexcept
178 { return a + (-b); }
179 inline lx_complex operator - (const lx_complex& a, const lx_real& b) noexcept
180 { return a + (-b); }
181 inline lx_complex operator - (const lx_complex& a, const l_real& b) noexcept
182 { return a + (-b); }
183 inline lx_complex operator - (const lx_complex& a, const real& b) noexcept
184 { return a + (-b); }
185 inline lx_complex operator - (const lx_real& a, const lx_complex& b) noexcept
186 { return a + (-b); }
187 inline lx_complex operator - (const l_real& a, const lx_complex& b) noexcept
188 { return a + (-b); }
189 inline lx_complex operator - (const real& a, const lx_complex& b) noexcept
190 { return a + (-b); }
191 
192 inline lx_complex & operator -=(lx_complex& a, const lx_complex& b) noexcept
193 { return a = a-b; }
194 inline lx_complex & operator -=(lx_complex& a, const l_complex& b) noexcept
195 { return a = a-b; }
196 inline lx_complex & operator -=(lx_complex& a, const complex& b) noexcept
197 { return a = a-b; }
198 inline lx_complex & operator -=(lx_complex& a, const lx_real& b) noexcept
199 { return a = a-b; }
200 inline lx_complex & operator -=(lx_complex& a, const l_real& b) noexcept
201 { return a = a-b; }
202 inline lx_complex & operator -=(lx_complex& a, const real& b) noexcept
203 { return a = a-b; }
204 
205 
206 inline lx_complex operator * (const lx_complex& a, const lx_complex& b) noexcept
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) noexcept
216 { return a*lx_complex(b); }
217 inline lx_complex operator * (const lx_complex& a, const complex& b) noexcept
218 { return a*lx_complex(b); }
219 inline lx_complex operator * (const l_complex& a, const lx_complex& b) noexcept
220 { return lx_complex(a)*b; }
221 inline lx_complex operator * (const complex& a, const lx_complex& b) noexcept
222 { return lx_complex(a)*b; }
223 inline lx_complex operator * (const lx_complex& a, const lx_real& b) noexcept
224 { return a*lx_complex(b); }
225 inline lx_complex operator * (const lx_complex& a, const l_real& b) noexcept
226 { return a*lx_complex(b); }
227 inline lx_complex operator * (const lx_complex& a, const real& b) noexcept
228 { return a*lx_complex(b); }
229 inline lx_complex operator * (const lx_real& a, const lx_complex& b) noexcept
230 { return lx_complex(a)*b; }
231 inline lx_complex operator * (const l_real& a, const lx_complex& b) noexcept
232 { return lx_complex(a)*b; }
233 inline lx_complex operator * (const real& a, const lx_complex& b) noexcept
234 { return lx_complex(a)*b; }
235 
236 inline lx_complex & operator *=(lx_complex& a, const lx_complex& b) noexcept
237 { return a = a*b; }
238 inline lx_complex & operator *=(lx_complex& a, const l_complex& b) noexcept
239 { return a = a*b; }
240 inline lx_complex & operator *=(lx_complex& a, const complex& b) noexcept
241 { return a = a*b; }
242 inline lx_complex & operator *=(lx_complex& a, const lx_real& b) noexcept
243 { return a = a*b; }
244 inline lx_complex & operator *=(lx_complex& a, const l_real& b) noexcept
245 { return a = a*b; }
246 inline lx_complex & operator *=(lx_complex& a, const real& b) noexcept
247 { return a = a*b; }
248 
249 
250 inline lx_complex operator / (const lx_complex& a, const lx_complex& b) noexcept
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) noexcept
260 { return a/lx_complex(b); }
261 inline lx_complex operator / (const lx_complex& a, const complex& b) noexcept
262 { return a/lx_complex(b); }
263 inline lx_complex operator / (const l_complex& a, const lx_complex& b) noexcept
264 { return lx_complex(a)/b; }
265 inline lx_complex operator / (const complex& a, const lx_complex& b) noexcept
266 { return lx_complex(a)/b; }
267 inline lx_complex operator / (const lx_complex& a, const lx_real& b) noexcept
268 { return a/lx_complex(b); }
269 inline lx_complex operator / (const lx_complex& a, const l_real& b) noexcept
270 { return a/lx_complex(b); }
271 inline lx_complex operator / (const lx_complex& a, const real& b) noexcept
272 { return a/lx_complex(b); }
273 inline lx_complex operator / (const lx_real& a, const lx_complex& b) noexcept
274 { return lx_complex(a)/b; }
275 inline lx_complex operator / (const l_real& a, const lx_complex& b) noexcept
276 { return lx_complex(a)/b; }
277 inline lx_complex operator / (const real& a, const lx_complex& b) noexcept
278 { return lx_complex(a)/b; }
279 
280 inline lx_complex & operator /=(lx_complex& a, const lx_complex& b) noexcept
281 { return a = a/b; }
282 inline lx_complex & operator /=(lx_complex& a, const l_complex& b) noexcept
283 { return a = a/b; }
284 inline lx_complex & operator /=(lx_complex& a, const complex& b) noexcept
285 { return a = a/b; }
286 inline lx_complex & operator /=(lx_complex& a, const lx_real& b) noexcept
287 { return a = a/b; }
288 inline lx_complex & operator /=(lx_complex& a, const l_real& b) noexcept
289 { return a = a/b; }
290 inline lx_complex & operator /=(lx_complex& a, const real& b) noexcept
291 { return a = a/b; }
292 
293 // --------------------------- Output ---------------------------------
294 
295 inline std::ostream& operator << (std::ostream& s, const lx_complex& a)
296  noexcept
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) noexcept
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
The Scalar Type complex.
Definition: complex.hpp:50
The Multiple-Precision Data Type l_complex.
Definition: l_complex.hpp:46
The Multiple-Precision Data Type l_real.
Definition: l_real.hpp:78
The Scalar Type real.
Definition: real.hpp:114
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) noexcept
Implementation of division operation.
Definition: cimatrix.inl:730
cdotprecision & operator+=(cdotprecision &cd, const l_complex &lc) noexcept
Implementation of standard algebraic addition and allocation operation.
Definition: cdot.inl:251
cimatrix & operator*=(cimatrix &m, const cinterval &c) noexcept
Implementation of multiplication and allocation operation.
Definition: cimatrix.inl:1605
civector operator*(const cimatrix_subv &rv, const cinterval &s) noexcept
Implementation of multiplication operation.
Definition: cimatrix.inl:731
cimatrix & operator/=(cimatrix &m, const cinterval &c) noexcept
Implementation of division and allocation operation.
Definition: cimatrix.inl:1623