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 
26 namespace cxsc {
27 
28 // ---- Konstruktoren ----
29 
31  : re(a), im(b), k(0) { re.set_k(0); im.set_k(0); }
32 
33 inline 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 
39 inline 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 }
138 inline cdotprecision _cdotprecision(const real& a, const real& b)
139 {
140  return cdotprecision (a,b);
141 }
142 
148 inline 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 
165 inline cdotprecision operator-(const cdotprecision &a) throw()
166 {
167  return cdotprecision (-a.re, -a.im);
168 }
169 inline cdotprecision operator+(const cdotprecision &a) throw()
170 {
171  return a;
172 }
173 
174 inline cdotprecision operator+(const cdotprecision &a,const cdotprecision &b) throw()
175 {
176  return cdotprecision(a.re+b.re,a.im+b.im);
177 }
178 inline cdotprecision operator-(const cdotprecision &a,const cdotprecision &b) throw()
179 {
180  return cdotprecision(a.re-b.re,a.im-b.im);
181 }
182 
183 inline cdotprecision operator +(const cdotprecision &a,const complex &b) throw() { return cdotprecision(a.re+Re(b),a.im+Im(b)); }
184 inline cdotprecision operator +(const complex &b,const cdotprecision &a) throw() { return cdotprecision(a.re+Re(b),a.im+Im(b)); }
185 inline cdotprecision operator -(const cdotprecision &a,const complex &b) throw() { return cdotprecision(a.re-Re(b),a.im-Im(b)); }
186 inline cdotprecision operator -(const complex &a,const cdotprecision &b) throw() { return cdotprecision(Re(a)-b.re,Im(a)-b.im); }
187 
188 inline cdotprecision operator +(const cdotprecision &a,const dotprecision &b) throw() { return cdotprecision(a.re+b,a.im); }
189 inline cdotprecision operator +(const dotprecision &b,const cdotprecision &a) throw() { return cdotprecision(a.re+b,a.im); }
190 inline cdotprecision operator -(const cdotprecision &a,const dotprecision &b) throw() { return cdotprecision(a.re-b,a.im); }
191 inline cdotprecision operator -(const dotprecision &a,const cdotprecision &b) throw() { return cdotprecision(a-b.re,-b.im); }
192 
193 inline cdotprecision operator +(const cdotprecision &a,const real &b) throw() { return cdotprecision(a.re+b,a.im); }
194 inline cdotprecision operator +(const real &b,const cdotprecision &a) throw() { return cdotprecision(a.re+b,a.im); }
195 inline cdotprecision operator -(const cdotprecision &a,const real &b) throw() { return cdotprecision(a.re-b,a.im); }
196 inline cdotprecision operator -(const real &a,const cdotprecision &b) throw() { return cdotprecision(a-b.re,b.im); }
197 
198 inline cdotprecision operator +(const cdotprecision &a, const l_real &b) throw()
199 {
200  return cdotprecision(a.re+b,a.im);
201 }
202 inline cdotprecision operator +(const l_real &b, const cdotprecision &a) throw()
203 {
204  return cdotprecision(a.re+b,a.im);
205 }
206 inline cdotprecision operator -(const cdotprecision &a, const l_real &b) throw()
207 {
208  return cdotprecision(a.re-b,a.im);
209 }
210 inline cdotprecision operator -(const l_real &b, const cdotprecision &a) throw()
211 {
212  return cdotprecision(b-a.re,-a.im);
213 }
214 
215 inline cdotprecision & operator +=(cdotprecision &a,const cdotprecision &b) throw() { a.re+=b.re;a.im+=b.im; return a;}
216 inline cdotprecision & operator +=(cdotprecision &a,const dotprecision &b) throw() { a.re+=b; return a;}
217 inline cdotprecision & operator -=(cdotprecision &a,const cdotprecision &b) throw() { a.re-=b.re;a.im-=b.im; return a;}
218 inline cdotprecision & operator -=(cdotprecision &a,const dotprecision &b) throw() { a.re-=b; return a;}
219 inline cdotprecision & operator +=(cdotprecision &a,const complex &b) throw()
220 {
221  a.re+=Re(b);
222  a.im+=Im(b);
223  return a;
224 }
225 inline cdotprecision & operator -=(cdotprecision &a,const complex &b) throw()
226 {
227  a.re-=Re(b);
228  a.im-=Im(b);
229  return a;
230 }
231 inline cdotprecision & operator +=(cdotprecision &a,const real &b) throw()
232 {
233  a.re+=b;
234  return a;
235 }
236 inline cdotprecision & operator -=(cdotprecision &a,const real &b) throw()
237 {
238  a.re-=b;
239  return a;
240 }
241 inline cdotprecision & operator +=(cdotprecision &a,const l_real &b) throw()
242 { // Blomquist 17.09.02.
243  a.re+=b;
244  return a;
245 }
246 inline cdotprecision & operator -=(cdotprecision &a,const l_real &b) throw()
247 { // Blomquist 17.09.02.
248  a.re-=b;
249  return a;
250 }
251 inline cdotprecision & operator += (cdotprecision &cd, const l_complex &lc) throw()
252 {
253  cd = cd + cdotprecision(lc); return cd;
254 }
255 inline cdotprecision & operator -= (cdotprecision &cd, const l_complex &lc) throw()
256 {
257  cd = cd - cdotprecision(lc); return cd;
258 }
259 
260 // --- Vergleichsoperationen ----
261 inline bool operator ==(const cdotprecision &a,const cdotprecision &b) throw() { return(a.re==b.re && a.im==b.im); }
262 inline bool operator !=(const cdotprecision &a,const cdotprecision &b) throw() { return(a.re!=b.re || a.im!=b.im); }
263 inline bool operator ==(const dotprecision &r,const cdotprecision &a) throw() { return(r==a.re && !a.im); }
264 inline bool operator !=(const dotprecision &r,const cdotprecision &a) throw() { return(r!=a.re || !!a.im); }
265 inline bool operator ==(const cdotprecision &a,const dotprecision &r) throw() { return(r==a.re && !a.im); }
266 inline bool operator !=(const cdotprecision &a,const dotprecision &r) throw() { return(r!=a.re || !!a.im); }
267 inline bool operator ==(const complex &c,const cdotprecision &a) throw() { return(Re(c)==a.re && Im(c)==a.im); }
268 inline bool operator !=(const complex &c,const cdotprecision &a) throw() { return(Re(c)!=a.re || Im(c)!=a.im); }
269 inline bool operator ==(const cdotprecision &a,const complex &c) throw() { return(Re(c)==a.re && Im(c)==a.im); }
270 inline bool operator !=(const cdotprecision &a,const complex &c) throw() { return(Re(c)!=a.re || Im(c)!=a.im); }
271 inline bool operator ==(const real &c,const cdotprecision &a) throw() { return(c==a.re && !a.im); }
272 inline bool operator !=(const real &c,const cdotprecision &a) throw() { return(c!=a.re || !!a.im); }
273 inline bool operator ==(const cdotprecision &a,const real &c) throw() { return(c==a.re && !a.im); }
274 inline bool operator !=(const cdotprecision &a,const real &c) throw() { return(c!=a.re || !!a.im); }
275 
276 inline bool operator ==(const l_real &c,const cdotprecision &a) throw()
277 {
278  return(c==a.re && !a.im);
279 }
280 
281 inline bool operator !=(const l_real &c,const cdotprecision &a) throw()
282 {
283  return(c!=a.re || !!a.im);
284 }
285 
286 inline bool operator ==(const cdotprecision &a,const l_real &c) throw()
287 {
288  return(c==a.re && !a.im);
289 }
290 
291 inline bool operator !=(const cdotprecision &a,const l_real &c) throw()
292 {
293  return(c!=a.re || !!a.im);
294 }
295 
296 // ----- Funktionen -----
298 {
299  return a.re;
300 }
301 
302 inline dotprecision & Im(cdotprecision& a) throw()
303 {
304  return a.im;
305 }
306 
307 inline const dotprecision & Re(const cdotprecision& a)
308 {
309  return a.re;
310 }
311 
312 inline const dotprecision & Im(const cdotprecision& a) throw()
313 {
314  return a.im;
315 }
316 
317 inline cdotprecision& SetRe (cdotprecision& a, const dotprecision& b) throw()
318 { // ggf. exception
319  a.re=b;
320  return a;
321 }
322 
323 inline cdotprecision& SetIm (cdotprecision& a, const dotprecision& b) throw()
324 {
325  a.im=b;
326  return a;
327 }
328 
329 inline cdotprecision conj(const cdotprecision& a) throw()
330 {
331  return cdotprecision(a.re,-a.im);
332 }
333 
334 inline bool operator !(const cdotprecision &a) throw()
335 {
336  return !a.re && !a.im;
337 }
338 
339 inline void accumulate (cdotprecision & a, const complex & b, const real & c) throw()
340 {
341  accumulate(a,b,complex(c));
342 }
343 
344 inline void accumulate (cdotprecision & a, const real & b, const complex & c) throw()
345 {
346  accumulate(a,complex(b),c);
347 }
348 
349 inline void accumulate (cdotprecision & a, const real & b, const real & c) throw()
350 {
351  accumulate(a,complex(b),complex(c));
352 }
353 
354 } // namespace cxsc
355 
cxsc::cdotprecision::cdotprecision
cdotprecision()
Constructor of class cdotprecision.
Definition: cdot.hpp:70
cxsc::cdotprecision::operator=
cdotprecision & operator=(const real &a)
Implementation of standard assigning operator.
Definition: cdot.inl:60
cxsc::_cdotprecision
cdotprecision _cdotprecision(const l_complex &)
Definition: cdot.inl:158
cxsc::l_complex
The Multiple-Precision Data Type l_complex.
Definition: l_complex.hpp:46
cxsc::dotprecision
The Data Type dotprecision.
Definition: dot.hpp:112
cxsc::dotprecision::set_k
void set_k(unsigned int i)
Set precision for computation of dot products.
Definition: dot.hpp:131
cxsc
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition: cdot.cpp:29
cxsc::operator+=
cdotprecision & operator+=(cdotprecision &cd, const l_complex &lc)
Implementation of standard algebraic addition and allocation operation.
Definition: cdot.inl:251
cxsc::l_real
The Multiple-Precision Data Type l_real.
Definition: l_real.hpp:78
cxsc::cdotprecision::Im
friend dotprecision & Im(cdotprecision &a)
Returns the imaginary part of the complex dotprecision value.
Definition: cdot.inl:302
cxsc::cdotprecision::Re
friend dotprecision & Re(cdotprecision &a)
Returns the real part of the complex dotprecision value.
Definition: cdot.inl:297
cxsc::cdotprecision
The Data Type cdotprecision.
Definition: cdot.hpp:61
cxsc::complex
The Scalar Type complex.
Definition: complex.hpp:50
cxsc::real
The Scalar Type real.
Definition: real.hpp:114