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) noexcept {}
61  complex(const real & a,const real & b) noexcept : re(a), im(b) { }
62 
64  inline complex & operator= (const real & r) noexcept;
65 
66  // ---- Type-Casts ---------------------------------------
67 
69  explicit inline complex(const real &r) noexcept : re(r),im(0.0) { }
70 
71 
72 // friend inline complex _complex(const real &a) noexcept { return complex(a,0.0); }
73 // friend inline complex _complex(const real &a,const real &b) noexcept{ return complex(a,b); }
74 
75 
76  // The following are defined in the specific vector, matrix-files
77 #if(CXSC_INDEX_CHECK)
79  explicit INLINE complex(const cvector &) ;
81  explicit INLINE complex(const cvector_slice &);
83  explicit INLINE complex(const cmatrix &) ;
85  explicit INLINE complex(const cmatrix_slice &);
87 
92  friend INLINE complex _complex(const cvector &) ;
94 
99  friend INLINE complex _complex(const cvector_slice &);
101 
106  friend INLINE complex _complex(const cmatrix &) ;
108 
113  friend INLINE complex _complex(const cmatrix_slice &);
114 #else
116  explicit INLINE complex(const cvector &) noexcept;
118  explicit INLINE complex(const cvector_slice &) noexcept;
120  explicit INLINE complex(const cmatrix &) noexcept;
122  explicit INLINE complex(const cmatrix_slice &) noexcept;
124 
129  friend INLINE complex _complex(const cvector &) noexcept;
131 
136  friend INLINE complex _complex(const cvector_slice &) noexcept;
138 
143  friend INLINE complex _complex(const cmatrix &) noexcept;
145 
150  friend INLINE complex _complex(const cmatrix_slice &) noexcept;
151 #endif
153  explicit complex(const cdotprecision &) noexcept;
155 
160  friend inline complex _complex(const cdotprecision &a) noexcept { return complex(a); }
161 
163  complex & operator =(const cdotprecision &) noexcept;
164 
165  // ---- Input/Output ---------------------------------------
167  friend std::ostream & operator <<(std::ostream &,const complex &) noexcept;
169  friend std::istream & operator >>(std::istream &,complex &) noexcept;
171  friend std::string & operator <<(std::string &,const complex &) noexcept;
173  friend std::string & operator >>(std::string &,complex &) noexcept;
175  friend void operator >>(const char *,complex &) noexcept;
177  friend void operator >>(const std::string &,complex &) noexcept;
178 
179  // ---- Std.Operators ---------------------------------------
181  friend inline complex operator -(const complex &) noexcept;
183  friend inline complex operator +(const complex &) noexcept;
184 
186  friend inline complex operator +(const complex &,const complex &) noexcept;
188  friend inline complex operator -(const complex &,const complex &) noexcept;
190  friend complex operator *(const complex &,const complex &) noexcept;
192  friend complex operator /(const complex &,const complex &) noexcept;
193 
195  friend inline complex & operator +=(complex &, const complex &) noexcept;
197  friend inline complex & operator -=(complex &, const complex &) noexcept;
199  friend inline complex & operator *=(complex &, const complex &) noexcept;
201  friend inline complex & operator /=(complex &, const complex &) noexcept;
202 
204  friend inline complex operator +(const complex &,const real &) noexcept;
206  friend inline complex operator +(const real &,const complex &) noexcept;
208  friend inline complex operator -(const complex &,const real &) noexcept;
210  friend inline complex operator -(const real &,const complex &) noexcept;
212  friend inline complex operator *(const complex &,const real &) noexcept;
214  friend inline complex operator *(const real &,const complex &) noexcept;
216  friend inline complex operator /(const complex &,const real &) noexcept;
218  friend inline complex operator /(const real &,const complex &) noexcept;
219 
221  friend inline complex & operator +=(complex &, const real &) noexcept;
223  friend inline complex & operator -=(complex &, const real &) noexcept;
225  friend inline complex & operator *=(complex &, const real &) noexcept;
227  friend inline complex & operator /=(complex &, const real &) noexcept;
228 
229  // ---- Comp.Operat. ---------------------------------------
230 // inline operator void *() const noexcept { if(re) return (void *)1; if(im) return (void *)1; else return 0; }
232  friend inline bool operator! (const complex & a) noexcept;
234  friend inline bool operator== (const complex & a, const complex & b) noexcept;
236  friend inline bool operator!= (const complex & a, const complex & b) noexcept;
238  friend inline bool operator== (const complex & a, const real & b) noexcept;
240  friend inline bool operator== (const real & a, const complex & b) noexcept;
242  friend inline bool operator!= (const complex & a, const real & b) noexcept;
244  friend inline bool operator!= (const real & a, const complex & b) noexcept;
245 
247  friend bool operator== (const complex & a, const dotprecision & b) noexcept;
249  friend bool operator== (const dotprecision & a, const complex & b) noexcept;
251  friend bool operator!= (const complex & a, const dotprecision & b) noexcept;
253  friend bool operator!= (const dotprecision & a, const complex & b) noexcept;
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) noexcept;
273  friend real abs2(const complex &) noexcept;
275  friend inline complex conj(const complex &) noexcept;
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 &) noexcept;
288  friend inline complex divu(const complex &, const real &) noexcept;
290  friend inline complex divd(const real &, const complex &) noexcept;
292  friend inline complex divu(const real &, const complex &) noexcept;
293 
295  friend complex muld (const complex &, const complex &) noexcept;
297  friend complex mulu (const complex &, const complex &) noexcept;
299  friend inline complex muld(const complex &, const real &) noexcept;
301  friend inline complex mulu(const complex &, const real &) noexcept;
303  friend inline complex muld(const real &, const complex &) noexcept;
305  friend inline complex mulu(const real &, const complex &) noexcept;
306 
307 
309  friend inline complex addd(const complex &, const complex &) noexcept;
311  friend inline complex addu(const complex &, const complex &) noexcept;
313  friend inline complex addd(const complex &, const real &) noexcept;
315  friend inline complex addu(const complex &, const real &) noexcept;
317  friend inline complex addd(const real &, const complex &) noexcept;
319  friend inline complex addu(const real &, const complex &) noexcept;
320 
321 
323  friend inline complex subd(const complex &, const complex &) noexcept;
325  friend inline complex subu(const complex &, const complex &) noexcept;
327  friend inline complex subd(const complex &, const real &) noexcept;
329  friend inline complex subu(const complex &, const real &) noexcept;
331  friend inline complex subd(const real &, const complex &) noexcept;
333  friend inline complex subu(const real &, const complex &) noexcept;
334 
336  complex & operator = (const lx_complex&) noexcept; // Blomquist, 12.11.2008;
338  complex & operator = (const l_complex&) noexcept; // 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 &) noexcept;
352 complex mulu (const complex &, const complex &) noexcept;
353 
354 // ---------------------------------------------------------------------------
355 // ---- ----
356 // ---- global functions associated with class real ----
357 // ---- ----
358 // ---------------------------------------------------------------------------
359 
361 
366 inline complex _complex(const real &a) noexcept { return complex(a,0.0); }
368 
373 inline complex _complex(const real &a,const real &b) noexcept{ 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&) noexcept;
392 complex sqrt(const complex&) noexcept;
394 complex sqrtp1m1(const complex&) noexcept;
396 complex sqrt1px2(const complex&) noexcept;
398 complex sqrtx2m1(const complex&) noexcept;
400 complex sqrt1mx2(const complex&) noexcept;
401 
403 complex exp(const complex&) noexcept;
405 complex expm1(const complex&) noexcept;
407 complex exp2(const complex&) noexcept;
409 complex exp10(const complex&) noexcept;
411 complex sin(const complex&) noexcept;
413 complex cos(const complex&) noexcept;
415 complex tan(const complex&) noexcept;
417 complex cot(const complex&) noexcept;
419 complex asin(const complex&) noexcept;
421 complex acos(const complex&) noexcept;
423 complex atan(const complex&) noexcept;
425 complex acot(const complex&) noexcept;
427 complex sinh(const complex&) noexcept;
429 complex cosh(const complex&) noexcept;
431 complex tanh(const complex&) noexcept;
433 complex coth(const complex&) noexcept;
435 complex asinh(const complex&) noexcept;
437 complex acosh(const complex&) noexcept;
439 complex atanh(const complex&) noexcept;
441 complex acoth(const complex&) noexcept;
443 std::list<complex>sqrt_all(const complex&);
445 complex sqrt(const complex&, int) noexcept;
447 real arg(const complex&) noexcept;
449 real Arg(const complex&) noexcept;
451 std::list<complex>sqrt_all(const complex&, int);
453 complex ln(const complex&) noexcept;
455 complex lnp1(const complex&) noexcept;
457 complex log2(const complex&) noexcept;
459 complex log10(const complex&) noexcept;
461 complex power(const complex&,int) noexcept;
463 complex power_fast(const complex&, int) noexcept;
465 complex pow(const complex&, const real&) noexcept;
467 complex pow(const complex&, const complex&) noexcept;
468 
469 } // namespace cxsc
470 
471 
472 #include "complex.inl"
473 
474 #endif
475 
The Data Type cdotprecision.
Definition: cdot.hpp:61
The Data Type cmatrix_slice.
Definition: cmatrix.hpp:1203
The Data Type cmatrix.
Definition: cmatrix.hpp:514
The Scalar Type complex.
Definition: complex.hpp:50
friend complex & operator*=(complex &, const complex &) noexcept
Implementation of standard algebraic multiplication and allocation operation.
Definition: complex.inl:60
friend real abs2(const complex &) noexcept
Returns the absolute value of a complex value.
Definition: complex.inl:526
friend real & Re(complex &a)
Returns the real part of the complex value.
Definition: complex.hpp:376
friend real & Im(complex &a)
Returns the imaginary part of the complex value.
Definition: complex.hpp:380
friend std::ostream & operator<<(std::ostream &, const complex &) noexcept
Implementation of standard output method.
Definition: complex.cpp:58
friend complex conj(const complex &) noexcept
Returns the conjugated complex value.
Definition: complex.inl:122
friend complex _complex(const cmatrix_slice &) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
complex(const real &a, const real &b) noexcept
Constructor of class complex.
Definition: complex.hpp:61
complex & operator=(const real &r) noexcept
Implementation of standard assigning operator.
Definition: complex.inl:31
friend complex & operator/=(complex &, const complex &) noexcept
Implementation of standard algebraic division and allocation operation.
Definition: complex.inl:61
friend bool operator!(const complex &a) noexcept
Implementation of standard negation operation.
Definition: complex.inl:112
complex(void) noexcept
Constructor of class complex.
Definition: complex.hpp:59
friend complex & SetRe(complex &a, const real &b)
Sets the real part of a complex value.
Definition: complex.hpp:385
friend real abs(complex) noexcept
Returns the absolute value of a complex value.
Definition: complex.inl:534
friend complex & SetIm(complex &a, const real &b)
Sets the imaginary part of a complex value.
Definition: complex.hpp:387
friend complex operator-(const complex &) noexcept
Implementation of standard algebraic negative sign operation.
Definition: complex.inl:38
friend complex divn(const complex &, const complex &)
Returns the nearest rounded result of the division operation.
Definition: complex.inl:501
friend complex operator/(const complex &, const complex &) noexcept
Implementation of standard algebraic division operation.
Definition: complex.inl:516
friend complex _complex(const cvector &) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
friend complex operator*(const complex &, const complex &) noexcept
Implementation of standard algebraic multiplication operation.
Definition: complex.inl:195
friend bool operator==(const complex &a, const complex &b) noexcept
Implementation of standard equality operation.
Definition: complex.inl:113
friend complex & operator-=(complex &, const complex &) noexcept
Implementation of standard algebraic subtraction and allocation operation.
Definition: complex.inl:59
friend bool operator!=(const complex &a, const complex &b) noexcept
Implementation of standard negated equality operation.
Definition: complex.inl:114
friend complex & operator+=(complex &, const complex &) noexcept
Implementation of standard algebraic addition and allocation operation.
Definition: complex.inl:58
complex(const real &r) noexcept
Constructor of class complex.
Definition: complex.hpp:69
complex(const cmatrix_slice &) noexcept
Constructor of class complex.
friend complex operator+(const complex &) noexcept
Implementation of standard algebraic positive sign operation.
Definition: complex.inl:43
friend complex _complex(const cvector_slice &) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
friend complex _complex(const cdotprecision &a) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
Definition: complex.hpp:160
friend std::istream & operator>>(std::istream &, complex &) noexcept
Implementation of standard input method.
Definition: complex.cpp:76
friend complex _complex(const cmatrix &) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
The Data Type cvector_slice.
Definition: cvector.hpp:845
The Data Type cvector.
Definition: cvector.hpp:58
The Data Type dotprecision.
Definition: dot.hpp:112
The Multiple-Precision Data Type l_complex.
Definition: l_complex.hpp:46
The Scalar Type real.
Definition: real.hpp:114
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition: cdot.cpp:29
cinterval sqrtp1m1(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:1054
complex _complex(const real &a) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
Definition: complex.hpp:366
cinterval exp2(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:167
cinterval sqrt1mx2(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:1140
cinterval asinh(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:2718
cinterval coth(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:578
cinterval log2(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:898
cinterval power(const cinterval &z, int n) noexcept
Calculates .
Definition: cimath.cpp:1941
cinterval log10(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:903
cinterval ln(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:851
cinterval pow(const cinterval &z, const interval &p) noexcept
Calculates .
Definition: cimath.cpp:2074
cinterval sinh(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:231
cinterval asin(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:2311
cinterval tan(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:393
cinterval exp10(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:172
interval arg(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:741
std::list< cinterval > sqrt_all(const cinterval &z)
Calculates and returns all possible solutions.
Definition: cimath.cpp:1176
cinterval acos(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:2553
cinterval sqrtx2m1(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:1109
cinterval acosh(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:2732
cinterval cosh(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:223
cinterval cos(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:207
cinterval sqrt1px2(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:1071
cinterval exp(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:159
cinterval tanh(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:565
cinterval expm1(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:177
cinterval cot(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:538
cinterval sqrt(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:1007
cinterval power_fast(const cinterval &z, int n) noexcept
Calculates .
Definition: cimath.cpp:1520
cinterval acot(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:3130
cinterval sqr(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:3342
cinterval lnp1(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:867
cinterval atan(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:2938
cinterval atanh(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:3317
interval Arg(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:654
cinterval acoth(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:3330
cinterval sin(const cinterval &z) noexcept
Calculates .
Definition: cimath.cpp:215