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