C-XSC - A C++ Class Library for Extended Scientific Computing 2.5.4
cdot.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: cdot.inl,v 1.31 2014/01/30 17:23:43 cxsc Exp $ */
25
26namespace cxsc {
27
28// ---- Konstruktoren ----
29
31 : re(a), im(b), k(0) { re.set_k(0); im.set_k(0); }
32
33inline cdotprecision::cdotprecision(const real &a,const real &b)
34 : re(a), im(b), k(0) {}
35
37 : re(a.re), im(a.im), k(a.k) {}
38
39inline cdotprecision::cdotprecision(const l_real &a, const l_real &b)
40 : re(a), im(b), k(0) {}
41
43 : re(Re(_cdotprecision(a))), im(Im(_cdotprecision(a))), k(0){}
44
46 : re(r), im(0), k(0) {}
47
49 : re(Re(c)),im(Im(c)), k(0) {}
50
52 : re(r), im(0), k(0) { re.set_k(0); im.set_k(0); }
53
55 : re(r), im(0), k(0) {}
56
57
58
59
61{
62 re=a;im=0; return *this;
63}
64
66{
67 re=Re(a),im=Im(a); return *this;
68}
70{
71 re=a;im=0; return *this;
72}
74{
75 re=a.re,im=a.im; return *this;
76}
78{
79 re=a;im=0; return *this;
80}
81
82
83// ---- Typwandlungen ----
84
91{
92 return cdotprecision (a);
93}
100{
101 return cdotprecision (a);
102}
103
110{
111 return cdotprecision (a);
112}
113
120{
121 return cdotprecision (a);
122}
123
130{
131 return cdotprecision (a,b);
132}
138inline cdotprecision _cdotprecision(const real& a, const real& b)
139{
140 return cdotprecision (a,b);
141}
142
148inline cdotprecision _cdotprecision(const l_real& a, const l_real& b)
149{
150 return cdotprecision (a,b);
151}
152
159{
160 return cdotprecision(lc);
161}
162
163// ---- Standardfunkt ---- (arithmetische Operatoren)
164
165inline cdotprecision operator-(const cdotprecision &a) noexcept
166{
167 return cdotprecision (-a.re, -a.im);
168}
169inline cdotprecision operator+(const cdotprecision &a) noexcept
170{
171 return a;
172}
173
174inline cdotprecision operator+(const cdotprecision &a,const cdotprecision &b) noexcept
175{
176 return cdotprecision(a.re+b.re,a.im+b.im);
177}
178inline cdotprecision operator-(const cdotprecision &a,const cdotprecision &b) noexcept
179{
180 return cdotprecision(a.re-b.re,a.im-b.im);
181}
182
183inline cdotprecision operator +(const cdotprecision &a,const complex &b) noexcept { return cdotprecision(a.re+Re(b),a.im+Im(b)); }
184inline cdotprecision operator +(const complex &b,const cdotprecision &a) noexcept { return cdotprecision(a.re+Re(b),a.im+Im(b)); }
185inline cdotprecision operator -(const cdotprecision &a,const complex &b) noexcept { return cdotprecision(a.re-Re(b),a.im-Im(b)); }
186inline cdotprecision operator -(const complex &a,const cdotprecision &b) noexcept { return cdotprecision(Re(a)-b.re,Im(a)-b.im); }
187
188inline cdotprecision operator +(const cdotprecision &a,const dotprecision &b) noexcept { return cdotprecision(a.re+b,a.im); }
189inline cdotprecision operator +(const dotprecision &b,const cdotprecision &a) noexcept { return cdotprecision(a.re+b,a.im); }
190inline cdotprecision operator -(const cdotprecision &a,const dotprecision &b) noexcept { return cdotprecision(a.re-b,a.im); }
191inline cdotprecision operator -(const dotprecision &a,const cdotprecision &b) noexcept { return cdotprecision(a-b.re,-b.im); }
192
193inline cdotprecision operator +(const cdotprecision &a,const real &b) noexcept { return cdotprecision(a.re+b,a.im); }
194inline cdotprecision operator +(const real &b,const cdotprecision &a) noexcept { return cdotprecision(a.re+b,a.im); }
195inline cdotprecision operator -(const cdotprecision &a,const real &b) noexcept { return cdotprecision(a.re-b,a.im); }
196inline cdotprecision operator -(const real &a,const cdotprecision &b) noexcept { return cdotprecision(a-b.re,b.im); }
197
198inline cdotprecision operator +(const cdotprecision &a, const l_real &b) noexcept
199{
200 return cdotprecision(a.re+b,a.im);
201}
202inline cdotprecision operator +(const l_real &b, const cdotprecision &a) noexcept
203{
204 return cdotprecision(a.re+b,a.im);
205}
206inline cdotprecision operator -(const cdotprecision &a, const l_real &b) noexcept
207{
208 return cdotprecision(a.re-b,a.im);
209}
210inline cdotprecision operator -(const l_real &b, const cdotprecision &a) noexcept
211{
212 return cdotprecision(b-a.re,-a.im);
213}
214
215inline cdotprecision & operator +=(cdotprecision &a,const cdotprecision &b) noexcept { a.re+=b.re;a.im+=b.im; return a;}
216inline cdotprecision & operator +=(cdotprecision &a,const dotprecision &b) noexcept { a.re+=b; return a;}
217inline cdotprecision & operator -=(cdotprecision &a,const cdotprecision &b) noexcept { a.re-=b.re;a.im-=b.im; return a;}
218inline cdotprecision & operator -=(cdotprecision &a,const dotprecision &b) noexcept { a.re-=b; return a;}
219inline cdotprecision & operator +=(cdotprecision &a,const complex &b) noexcept
220{
221 a.re+=Re(b);
222 a.im+=Im(b);
223 return a;
224}
225inline cdotprecision & operator -=(cdotprecision &a,const complex &b) noexcept
226{
227 a.re-=Re(b);
228 a.im-=Im(b);
229 return a;
230}
231inline cdotprecision & operator +=(cdotprecision &a,const real &b) noexcept
232{
233 a.re+=b;
234 return a;
235}
236inline cdotprecision & operator -=(cdotprecision &a,const real &b) noexcept
237{
238 a.re-=b;
239 return a;
240}
241inline cdotprecision & operator +=(cdotprecision &a,const l_real &b) noexcept
242{ // Blomquist 17.09.02.
243 a.re+=b;
244 return a;
245}
246inline cdotprecision & operator -=(cdotprecision &a,const l_real &b) noexcept
247{ // Blomquist 17.09.02.
248 a.re-=b;
249 return a;
250}
251inline cdotprecision & operator += (cdotprecision &cd, const l_complex &lc) noexcept
252{
253 cd = cd + cdotprecision(lc); return cd;
254}
255inline cdotprecision & operator -= (cdotprecision &cd, const l_complex &lc) noexcept
256{
257 cd = cd - cdotprecision(lc); return cd;
258}
259
260// --- Vergleichsoperationen ----
261inline bool operator ==(const cdotprecision &a,const cdotprecision &b) noexcept { return(a.re==b.re && a.im==b.im); }
262inline bool operator !=(const cdotprecision &a,const cdotprecision &b) noexcept { return(a.re!=b.re || a.im!=b.im); }
263inline bool operator ==(const dotprecision &r,const cdotprecision &a) noexcept { return(r==a.re && !a.im); }
264inline bool operator !=(const dotprecision &r,const cdotprecision &a) noexcept { return(r!=a.re || !!a.im); }
265inline bool operator ==(const cdotprecision &a,const dotprecision &r) noexcept { return(r==a.re && !a.im); }
266inline bool operator !=(const cdotprecision &a,const dotprecision &r) noexcept { return(r!=a.re || !!a.im); }
267inline bool operator ==(const complex &c,const cdotprecision &a) noexcept { return(Re(c)==a.re && Im(c)==a.im); }
268inline bool operator !=(const complex &c,const cdotprecision &a) noexcept { return(Re(c)!=a.re || Im(c)!=a.im); }
269inline bool operator ==(const cdotprecision &a,const complex &c) noexcept { return(Re(c)==a.re && Im(c)==a.im); }
270inline bool operator !=(const cdotprecision &a,const complex &c) noexcept { return(Re(c)!=a.re || Im(c)!=a.im); }
271inline bool operator ==(const real &c,const cdotprecision &a) noexcept { return(c==a.re && !a.im); }
272inline bool operator !=(const real &c,const cdotprecision &a) noexcept { return(c!=a.re || !!a.im); }
273inline bool operator ==(const cdotprecision &a,const real &c) noexcept { return(c==a.re && !a.im); }
274inline bool operator !=(const cdotprecision &a,const real &c) noexcept { return(c!=a.re || !!a.im); }
275
276inline bool operator ==(const l_real &c,const cdotprecision &a) noexcept
277{
278 return(c==a.re && !a.im);
279}
280
281inline bool operator !=(const l_real &c,const cdotprecision &a) noexcept
282{
283 return(c!=a.re || !!a.im);
284}
285
286inline bool operator ==(const cdotprecision &a,const l_real &c) noexcept
287{
288 return(c==a.re && !a.im);
289}
290
291inline bool operator !=(const cdotprecision &a,const l_real &c) noexcept
292{
293 return(c!=a.re || !!a.im);
294}
295
296// ----- Funktionen -----
298{
299 return a.re;
300}
301
302inline dotprecision & Im(cdotprecision& a) noexcept
303{
304 return a.im;
305}
306
307inline const dotprecision & Re(const cdotprecision& a)
308{
309 return a.re;
310}
311
312inline const dotprecision & Im(const cdotprecision& a) noexcept
313{
314 return a.im;
315}
316
317inline cdotprecision& SetRe (cdotprecision& a, const dotprecision& b) noexcept
318{ // ggf. exception
319 a.re=b;
320 return a;
321}
322
323inline cdotprecision& SetIm (cdotprecision& a, const dotprecision& b) noexcept
324{
325 a.im=b;
326 return a;
327}
328
329inline cdotprecision conj(const cdotprecision& a) noexcept
330{
331 return cdotprecision(a.re,-a.im);
332}
333
334inline bool operator !(const cdotprecision &a) noexcept
335{
336 return !a.re && !a.im;
337}
338
339inline void accumulate (cdotprecision & a, const complex & b, const real & c) noexcept
340{
341 accumulate(a,b,complex(c));
342}
343
344inline void accumulate (cdotprecision & a, const real & b, const complex & c) noexcept
345{
346 accumulate(a,complex(b),c);
347}
348
349inline void accumulate (cdotprecision & a, const real & b, const real & c) noexcept
350{
351 accumulate(a,complex(b),complex(c));
352}
353
354} // namespace cxsc
355
The Data Type cdotprecision.
Definition cdot.hpp:61
friend dotprecision & Re(cdotprecision &a)
Returns the real part of the complex dotprecision value.
Definition cdot.inl:297
cdotprecision()
Constructor of class cdotprecision.
Definition cdot.hpp:70
friend dotprecision & Im(cdotprecision &a) noexcept
Returns the imaginary part of the complex dotprecision value.
Definition cdot.inl:302
cdotprecision & operator=(const real &a)
Implementation of standard assigning operator.
Definition cdot.inl:60
The Scalar Type complex.
Definition complex.hpp:50
The Data Type dotprecision.
Definition dot.hpp:112
void set_k(unsigned int i)
Set precision for computation of dot products.
Definition dot.hpp:131
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
cdotprecision _cdotprecision(const l_complex &)
Definition cdot.inl:158