C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
complex.hpp
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: complex.hpp,v 1.32 2014/01/30 17:23:44 cxsc Exp $ */
25 
26 #ifndef _CXSC_COMPLEX_HPP_INCLUDED
27 #define _CXSC_COMPLEX_HPP_INCLUDED
28 
29 #include <iostream>
30 #include <string>
31 #include <list> // Blomquist, 02.12.2008;
32 #include "compiler.h"
33 #include "except.hpp"
34 #include "real.hpp"
35 
36 namespace cxsc {
37 
38 class cvector;
39 class cmatrix;
40 class cvector_slice;
41 class cmatrix_slice;
42 
43 
45 
49 class complex
50 {
51  private:
52  // ---- Datenelemente ---------------------------------------
53  real re;
54  real im;
55 
56  public:
57  // ---- Constructors ---------------------------------------
59  complex(void) throw () {}
61  complex(const real & a,const real & b) throw () : re(a), im(b) { }
62 
64  inline complex & operator= (const real & r) throw();
65 
66  // ---- Type-Casts ---------------------------------------
67 
69  explicit inline complex(const real &r) throw() : re(r),im(0.0) { }
70 
71 
72 // friend inline complex _complex(const real &a) throw () { return complex(a,0.0); }
73 // friend inline complex _complex(const real &a,const real &b) throw(){ return complex(a,b); }
74 
75 
76  // The following are defined in the specific vector, matrix-files
77 #if(CXSC_INDEX_CHECK)
78  explicit INLINE complex(const cvector &) throw (ERROR_CVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_CVECTOR_USE_OF_UNINITIALIZED_OBJ);
81  explicit INLINE complex(const cvector_slice &) throw (ERROR_CVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_CVECTOR_USE_OF_UNINITIALIZED_OBJ);
83  explicit INLINE complex(const cmatrix &) throw (ERROR_CMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_CMATRIX_USE_OF_UNINITIALIZED_OBJ);
85  explicit INLINE complex(const cmatrix_slice &) throw (ERROR_CMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_CMATRIX_USE_OF_UNINITIALIZED_OBJ);
87 
92  friend INLINE complex _complex(const cvector &) throw (ERROR_CVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_CVECTOR_USE_OF_UNINITIALIZED_OBJ);
94 
99  friend INLINE complex _complex(const cvector_slice &) throw (ERROR_CVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_CVECTOR_USE_OF_UNINITIALIZED_OBJ);
101 
106  friend INLINE complex _complex(const cmatrix &) throw (ERROR_CMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_CMATRIX_USE_OF_UNINITIALIZED_OBJ);
108 
113  friend INLINE complex _complex(const cmatrix_slice &) throw (ERROR_CMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_CMATRIX_USE_OF_UNINITIALIZED_OBJ);
114 #else
115  explicit INLINE complex(const cvector &) throw ();
118  explicit INLINE complex(const cvector_slice &) throw ();
120  explicit INLINE complex(const cmatrix &) throw ();
122  explicit INLINE complex(const cmatrix_slice &) throw ();
124 
129  friend INLINE complex _complex(const cvector &) throw ();
131 
136  friend INLINE complex _complex(const cvector_slice &) throw ();
138 
143  friend INLINE complex _complex(const cmatrix &) throw ();
145 
150  friend INLINE complex _complex(const cmatrix_slice &) throw ();
151 #endif
152  explicit complex(const cdotprecision &) throw();
155 
160  friend inline complex _complex(const cdotprecision &a) throw() { return complex(a); }
161 
163  complex & operator =(const cdotprecision &) throw();
164 
165  // ---- Input/Output ---------------------------------------
167  friend std::ostream & operator <<(std::ostream &,const complex &) throw();
169  friend std::istream & operator >>(std::istream &,complex &) throw();
171  friend std::string & operator <<(std::string &,const complex &) throw();
173  friend std::string & operator >>(std::string &,complex &) throw();
175  friend void operator >>(const char *,complex &) throw();
177  friend void operator >>(const std::string &,complex &) throw();
178 
179  // ---- Std.Operators ---------------------------------------
181  friend inline complex operator -(const complex &) throw ();
183  friend inline complex operator +(const complex &) throw ();
184 
186  friend inline complex operator +(const complex &,const complex &) throw();
188  friend inline complex operator -(const complex &,const complex &) throw();
190  friend complex operator *(const complex &,const complex &) throw();
192  friend complex operator /(const complex &,const complex &) throw();
193 
195  friend inline complex & operator +=(complex &, const complex &) throw();
197  friend inline complex & operator -=(complex &, const complex &) throw();
199  friend inline complex & operator *=(complex &, const complex &) throw();
201  friend inline complex & operator /=(complex &, const complex &) throw();
202 
204  friend inline complex operator +(const complex &,const real &) throw();
206  friend inline complex operator +(const real &,const complex &) throw();
208  friend inline complex operator -(const complex &,const real &) throw();
210  friend inline complex operator -(const real &,const complex &) throw();
212  friend inline complex operator *(const complex &,const real &) throw();
214  friend inline complex operator *(const real &,const complex &) throw();
216  friend inline complex operator /(const complex &,const real &) throw();
218  friend inline complex operator /(const real &,const complex &) throw();
219 
221  friend inline complex & operator +=(complex &, const real &) throw();
223  friend inline complex & operator -=(complex &, const real &) throw();
225  friend inline complex & operator *=(complex &, const real &) throw();
227  friend inline complex & operator /=(complex &, const real &) throw();
228 
229  // ---- Comp.Operat. ---------------------------------------
230 // inline operator void *() const throw() { if(re) return (void *)1; if(im) return (void *)1; else return 0; }
232  friend inline bool operator! (const complex & a) throw();
234  friend inline bool operator== (const complex & a, const complex & b) throw();
236  friend inline bool operator!= (const complex & a, const complex & b) throw();
238  friend inline bool operator== (const complex & a, const real & b) throw();
240  friend inline bool operator== (const real & a, const complex & b) throw();
242  friend inline bool operator!= (const complex & a, const real & b) throw();
244  friend inline bool operator!= (const real & a, const complex & b) throw();
245 
247  friend bool operator== (const complex & a, const dotprecision & b) throw();
249  friend bool operator== (const dotprecision & a, const complex & b) throw();
251  friend bool operator!= (const complex & a, const dotprecision & b) throw();
253  friend bool operator!= (const dotprecision & a, const complex & b) throw();
254 
255  // ---- Others -------------------------------------------
257  friend inline real & Re(complex & a); // { return a.re; }
259  friend inline real Re(const complex & a); // { return a.re; }
261  friend inline real & Im(complex & a); // { return a.im; }
263  friend inline real Im(const complex & a); // { return a.im; }
264 
266  friend inline complex & SetRe(complex & a,const real & b); // { a.re=b; return a; }
268  friend inline complex & SetIm(complex & a,const real & b); // { a.im=b; return a; }
269 
271  friend real abs(complex) throw();
273  friend real abs2(const complex &) throw();
275  friend inline complex conj(const complex &) throw();
276 
277 // -------------- Directed rounding, Blomquist 07.11.02 --------------------
278 
280  friend complex divn (const complex &, const complex &);
282  friend complex divd (const complex &, const complex &);
284  friend complex divu (const complex &, const complex &);
286  friend inline complex divd(const complex &, const real &) throw();
288  friend inline complex divu(const complex &, const real &) throw();
290  friend inline complex divd(const real &, const complex &) throw();
292  friend inline complex divu(const real &, const complex &) throw();
293 
295  friend complex muld (const complex &, const complex &) throw();
297  friend complex mulu (const complex &, const complex &) throw();
299  friend inline complex muld(const complex &, const real &) throw();
301  friend inline complex mulu(const complex &, const real &) throw();
303  friend inline complex muld(const real &, const complex &) throw();
305  friend inline complex mulu(const real &, const complex &) throw();
306 
307 
309  friend inline complex addd(const complex &, const complex &) throw();
311  friend inline complex addu(const complex &, const complex &) throw();
313  friend inline complex addd(const complex &, const real &) throw();
315  friend inline complex addu(const complex &, const real &) throw();
317  friend inline complex addd(const real &, const complex &) throw();
319  friend inline complex addu(const real &, const complex &) throw();
320 
321 
323  friend inline complex subd(const complex &, const complex &) throw();
325  friend inline complex subu(const complex &, const complex &) throw();
327  friend inline complex subd(const complex &, const real &) throw();
329  friend inline complex subu(const complex &, const real &) throw();
331  friend inline complex subd(const real &, const complex &) throw();
333  friend inline complex subu(const real &, const complex &) throw();
334 
336  complex & operator = (const lx_complex&) throw(); // Blomquist, 12.11.2008;
338  complex & operator = (const l_complex&) throw(); // Blomquist, 12.11.2008;
339 }; // end class complex
340 
341 
342 // ---------------------------------------------------------------------------
343 // ---- ----
344 // ---- friend functions of class real (not inline) ----
345 // ---- ----
346 // ---------------------------------------------------------------------------
347 
348 complex divn (const complex &, const complex &);
349 complex divd (const complex &, const complex &);
350 complex divu (const complex &, const complex &);
351 complex muld (const complex &, const complex &) throw();
352 complex mulu (const complex &, const complex &) throw();
353 
354 // ---------------------------------------------------------------------------
355 // ---- ----
356 // ---- global functions associated with class real ----
357 // ---- ----
358 // ---------------------------------------------------------------------------
359 
361 
366 inline complex _complex(const real &a) throw () { return complex(a,0.0); }
368 
373 inline complex _complex(const real &a,const real &b) throw(){ return complex(a,b); }
374 
376 inline real & Re(complex & z) { return z.re; }
378 inline real Re(const complex & z) { return z.re; }
380 inline real & Im(complex & z) { return z.im; }
382 inline real Im(const complex & z) { return z.im; }
383 
385 inline complex & SetRe(complex & z,const real & b) { z.re=b; return z; }
387 inline complex & SetIm(complex & z,const real & b) { z.im=b; return z; }
388 
390 inline complex sqr (const complex&) throw();
392 complex sqrt(const complex&) throw();
394 complex sqrtp1m1(const complex&) throw();
396 complex sqrt1px2(const complex&) throw();
398 complex sqrtx2m1(const complex&) throw();
400 complex sqrt1mx2(const complex&) throw();
401 
403 complex exp(const complex&) throw();
405 complex expm1(const complex&) throw();
407 complex exp2(const complex&) throw();
409 complex exp10(const complex&) throw();
411 complex sin(const complex&) throw();
413 complex cos(const complex&) throw();
415 complex tan(const complex&) throw();
417 complex cot(const complex&) throw();
419 complex asin(const complex&) throw();
421 complex acos(const complex&) throw();
423 complex atan(const complex&) throw();
425 complex acot(const complex&) throw();
427 complex sinh(const complex&) throw();
429 complex cosh(const complex&) throw();
431 complex tanh(const complex&) throw();
433 complex coth(const complex&) throw();
435 complex asinh(const complex&) throw();
437 complex acosh(const complex&) throw();
439 complex atanh(const complex&) throw();
441 complex acoth(const complex&) throw();
443 std::list<complex>sqrt_all(const complex&);
445 complex sqrt(const complex&, int) throw();
447 real arg(const complex&) throw();
449 real Arg(const complex&) throw();
451 std::list<complex>sqrt_all(const complex&, int);
453 complex ln(const complex&) throw();
455 complex lnp1(const complex&) throw();
457 complex log2(const complex&) throw();
459 complex log10(const complex&) throw();
461 complex power(const complex&,int) throw();
463 complex power_fast(const complex&, int) throw();
465 complex pow(const complex&, const real&) throw();
467 complex pow(const complex&, const complex&) throw();
468 
469 } // namespace cxsc
470 
471 
472 #include "complex.inl"
473 
474 #endif
475 
cinterval sqrtx2m1(const cinterval &z)
Calculates .
Definition: cimath.cpp:1109
complex & operator=(const real &r)
Implementation of standard assigning operator.
Definition: complex.inl:31
friend complex & operator+=(complex &, const complex &)
Implementation of standard algebraic addition and allocation operation.
Definition: complex.inl:58
friend complex operator -(const complex &)
Implementation of standard algebraic negative sign operation.
Definition: complex.inl:38
cinterval sqrt1px2(const cinterval &z)
Calculates .
Definition: cimath.cpp:1071
The Data Type dotprecision.
Definition: dot.hpp:111
cinterval log2(const cinterval &z)
Calculates .
Definition: cimath.cpp:898
cinterval ln(const cinterval &z)
Calculates .
Definition: cimath.cpp:851
cinterval sin(const cinterval &z)
Calculates .
Definition: cimath.cpp:215
cinterval cot(const cinterval &z)
Calculates .
Definition: cimath.cpp:538
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition: cdot.cpp:29
cinterval acot(const cinterval &z)
Calculates .
Definition: cimath.cpp:3130
friend complex _complex(const cvector &)
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
friend complex & operator/=(complex &, const complex &)
Implementation of standard algebraic division and allocation operation.
Definition: complex.inl:61
friend complex operator *(const complex &, const complex &)
Implementation of standard algebraic multiplication operation.
Definition: complex.inl:195
friend complex conj(const complex &)
Returns the conjugated complex value.
Definition: complex.inl:122
cinterval atan(const cinterval &z)
Calculates .
Definition: cimath.cpp:2938
cinterval acos(const cinterval &z)
Calculates .
Definition: cimath.cpp:2553
cinterval sqr(const cinterval &z)
Calculates .
Definition: cimath.cpp:3342
cinterval expm1(const cinterval &z)
Calculates .
Definition: cimath.cpp:177
The Data Type cvector.
Definition: cvector.hpp:57
cinterval tanh(const cinterval &z)
Calculates .
Definition: cimath.cpp:565
cinterval asinh(const cinterval &z)
Calculates .
Definition: cimath.cpp:2718
friend real & Im(complex &a)
Returns the imaginary part of the complex value.
Definition: complex.hpp:380
cinterval log10(const cinterval &z)
Calculates .
Definition: cimath.cpp:903
cinterval sqrt1mx2(const cinterval &z)
Calculates .
Definition: cimath.cpp:1140
The Data Type cmatrix.
Definition: cmatrix.hpp:513
friend complex & SetRe(complex &a, const real &b)
Sets the real part of a complex value.
Definition: complex.hpp:385
friend complex operator/(const complex &, const complex &)
Implementation of standard algebraic division operation.
Definition: complex.inl:516
friend complex & operator -=(complex &, const complex &)
Implementation of standard algebraic subtraction and allocation operation.
Definition: complex.inl:59
The Data Type cdotprecision.
Definition: cdot.hpp:60
cinterval lnp1(const cinterval &z)
Calculates .
Definition: cimath.cpp:867
complex(const real &r)
Constructor of class complex.
Definition: complex.hpp:69
std::list< cinterval > sqrt_all(const cinterval &z)
Calculates and returns all possible solutions.
Definition: cimath.cpp:1176
friend real abs(complex)
Returns the absolute value of a complex value.
Definition: complex.inl:534
complex _complex(const real &a)
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
Definition: complex.hpp:366
friend complex operator+(const complex &)
Implementation of standard algebraic positive sign operation.
Definition: complex.inl:43
friend complex divn(const complex &, const complex &)
Returns the nearest rounded result of the division operation.
Definition: complex.inl:501
friend std::istream & operator >>(std::istream &, complex &)
Implementation of standard input method.
Definition: complex.cpp:76
cinterval sqrt(const cinterval &z)
Calculates .
Definition: cimath.cpp:1007
The Multiple-Precision Data Type l_complex.
Definition: l_complex.hpp:45
The Scalar Type complex.
Definition: complex.hpp:49
cinterval cos(const cinterval &z)
Calculates .
Definition: cimath.cpp:207
friend real abs2(const complex &)
Returns the absolute value of a complex value.
Definition: complex.inl:526
The Data Type cmatrix_slice.
Definition: cmatrix.hpp:1202
cinterval atanh(const cinterval &z)
Calculates .
Definition: cimath.cpp:3317
cinterval power_fast(const cinterval &z, int n)
Calculates .
Definition: cimath.cpp:1520
friend bool operator!(const complex &a)
Implementation of standard negation operation.
Definition: complex.inl:112
cinterval exp10(const cinterval &z)
Calculates .
Definition: cimath.cpp:172
cinterval sqrtp1m1(const cinterval &z)
Calculates .
Definition: cimath.cpp:1054
cinterval exp(const cinterval &z)
Calculates .
Definition: cimath.cpp:159
cinterval cosh(const cinterval &z)
Calculates .
Definition: cimath.cpp:223
cinterval tan(const cinterval &z)
Calculates .
Definition: cimath.cpp:393
complex(void)
Constructor of class complex.
Definition: complex.hpp:59
friend complex _complex(const cdotprecision &a)
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
Definition: complex.hpp:160
cinterval sinh(const cinterval &z)
Calculates .
Definition: cimath.cpp:231
cinterval exp2(const cinterval &z)
Calculates .
Definition: cimath.cpp:167
interval Arg(const cinterval &z)
Calculates .
Definition: cimath.cpp:654
cinterval asin(const cinterval &z)
Calculates .
Definition: cimath.cpp:2311
friend bool operator==(const complex &a, const complex &b)
Implementation of standard equality operation.
Definition: complex.inl:113
cinterval acoth(const cinterval &z)
Calculates .
Definition: cimath.cpp:3330
The Data Type cvector_slice.
Definition: cvector.hpp:844
cinterval coth(const cinterval &z)
Calculates .
Definition: cimath.cpp:578
cinterval pow(const cinterval &z, const interval &p)
Calculates .
Definition: cimath.cpp:2074
interval arg(const cinterval &z)
Calculates .
Definition: cimath.cpp:741
friend complex & operator *=(complex &, const complex &)
Implementation of standard algebraic multiplication and allocation operation.
Definition: complex.inl:60
complex(const real &a, const real &b)
Constructor of class complex.
Definition: complex.hpp:61
The Scalar Type real.
Definition: real.hpp:113
cinterval power(const cinterval &z, int n)
Calculates .
Definition: cimath.cpp:1941
friend bool operator!=(const complex &a, const complex &b)
Implementation of standard negated equality operation.
Definition: complex.inl:114
friend std::ostream & operator<<(std::ostream &, const complex &)
Implementation of standard output method.
Definition: complex.cpp:58
friend real & Re(complex &a)
Returns the real part of the complex value.
Definition: complex.hpp:376
cinterval acosh(const cinterval &z)
Calculates .
Definition: cimath.cpp:2732
friend complex & SetIm(complex &a, const real &b)
Sets the imaginary part of a complex value.
Definition: complex.hpp:387