C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
lx_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: lx_complex.hpp,v 1.9 2014/01/30 17:23:47 cxsc Exp $ */
25 
26 
27 /*
28 ** F. Blomquist, University of Wuppertal, 19.09.2007;
29 */
30 
31 /*
32 ** Implementation of the classes
33 **
34 ** lx_complex with all tools and elementary functions for complex
35 ** point and interval aruments
36 **
37 */
38 
39 #ifndef _CXSC_LX_COMPLEX_HPP_INCLUDED
40 #define _CXSC_LX_COMPLEX_HPP_INCLUDED
41 
42 #include <iostream>
43 #include <except.hpp>
44 #include <l_cinterval.hpp>
45 #include <l_complex.hpp>
46 #include "lx_interval.hpp"
47 
48 namespace cxsc {
49 // --------------------------------------------------------------------------
50 // Class lx_complex
51 // --------------------------------------------------------------------------
52 
53  class lx_complex
54  {
55  private:
56  // ------------- Data Elements -------------------------------------------
57  lx_real re;
58  lx_real im;
59 
60  public:
61  // ------------- Constructors --------------------------------------------
62 
64  lx_complex(void) throw() {}
66  lx_complex(const real& nr, const l_real &ar, const real& ni, const l_real &ai)
67  throw() : re(lx_real(nr,ar)), im(lx_real(ni,ai)) { }
69  lx_complex(const real& n, const real &a)
70  throw() : re(lx_real(n,a)), im(lx_real(0.0)) { }
72  lx_complex(const lx_real &a, const lx_real &b)
73  throw() : re(a), im(b) { }
75  lx_complex(const lx_real &a) throw() : re(a), im(lx_real(0.0)) { }
77  explicit lx_complex(const l_real &a, const l_real &b)
78  throw() : re(a), im(b) { }
80  explicit lx_complex(const l_real &a)
81  throw() : re(a), im(lx_real(0.0)) { }
83  explicit lx_complex(const real &a)
84  throw() : re(a), im(lx_real(0.0)) { }
86  explicit lx_complex(const complex &a)
87  throw() : re(Re(a)), im(Im(a)) { }
89  explicit lx_complex(const l_complex &a)
90  throw() : re(lx_real(0,Re(a))), im(lx_real(0,Im(a))) { }
92  lx_complex(const real& pr, const string& sr,
93  const real& pi, const string& si)
94  throw() : re(lx_real(pr,sr)), im(lx_real(pi,si)) { }
95 
96 // ------------- Assignments ---------------------------------------------
98  lx_complex & operator = (const lx_real & lr) throw()
99  { re = lr; im = 0; return *this; }
101  lx_complex & operator = (const l_real & lr) throw()
102  { re = lr; im = 0; return *this; }
104  lx_complex & operator = (const real & lr) throw()
105  { re = lr; im = 0; return *this; }
107  lx_complex & operator = (const l_complex & c) throw()
108  { re = Re(c); im = Im(c); return *this; }
110  lx_complex & operator = (const complex & c) throw()
111  { re = Re(c); im = Im(c); return *this; }
112 
113  // ------------- Functions -----------------------------------------------
114 
116  friend inline lx_real Re(const lx_complex&);
118  friend inline lx_real Im(const lx_complex&);
120  friend inline int StagPrec(const lx_complex&) throw();
122  friend inline real expoRe(const lx_complex&) throw();
124  friend inline real expoIm(const lx_complex&) throw();
126  friend inline l_real lr_partRe(const lx_complex&) throw();
128  friend inline l_real lr_partIm(const lx_complex&) throw();
129 
131  friend inline lx_complex & SetRe(lx_complex&, const lx_real&);
133  friend inline lx_complex & SetRe(lx_complex&, const l_real&);
135  friend inline lx_complex & SetRe(lx_complex&, const real&);
136 
138  friend inline lx_complex & SetIm(lx_complex&, const lx_real&);
140  friend inline lx_complex & SetIm(lx_complex&, const l_real&);
142  friend inline lx_complex & SetIm(lx_complex&, const real&);
143 
145  friend inline lx_complex conj(const lx_complex& a) throw();
147  friend lx_real abs (const lx_complex&) throw();
149  friend lx_real abs2 (const lx_complex&) throw();
150 
152  friend inline bool operator ! (const lx_complex& ) throw();
153 
155  friend inline bool operator == (const lx_complex&, const lx_complex&)
156  throw();
158  friend inline bool operator == (const lx_complex&, const l_complex&)
159  throw();
161  friend inline bool operator == (const lx_complex&, const complex&)
162  throw();
164  friend inline bool operator == (const l_complex&, const lx_complex&)
165  throw();
167  friend inline bool operator == (const complex&, const lx_complex&)
168  throw();
170  friend inline bool operator == (const lx_complex&, const lx_real&) throw();
172  friend inline bool operator == (const lx_complex&, const l_real&) throw();
174  friend inline bool operator == (const lx_complex&, const real&) throw();
176  friend inline bool operator == (const lx_real&, const lx_complex&) throw();
178  friend inline bool operator == (const l_real&, const lx_complex&) throw();
180  friend inline bool operator == (const real&, const lx_complex&) throw();
181 
183  friend inline lx_complex operator - (const lx_complex &) throw();
184 
185 
186 // ----------------------- Output --------------------------------------------
187 
189  friend inline std::ostream& operator << (std::ostream& s, const lx_complex& a)
190  throw(); // A value a of type lx_complex is written to the output channel.
192  friend inline std::string & operator << (std::string &s, const lx_complex& a)
193  throw();
194 // The value of a variable a of type lx_complex is copied to a string s.
195 // s has the form: ({2**()*...} , {2**()*...})
196 
197 // ----------------------- Input --------------------------------------------
198 
200  friend std::string & operator >> (std::string& s, lx_complex& a) throw();
201 
203 friend std::istream & operator >> (std::istream &s, lx_complex &a) throw()
204 // An input of a complex number z of the form ({...,...},{...,...}) is
205 // copied to the variable a of type lx_complex.
206 {
207  char c;
208  std::cout << "Real part: {Exponent to base 10, real number} = ?"
209  << std::endl;
210  s >> a.re;
211  std::cout << "Img. part: {Exponent to base 10, real number} = ?"
212  << std::endl;
213  s >> a.im >> RestoreOpt;
214 
215  if (!waseolnflag)
216  {
217  skipeolnflag = false, inpdotflag = true;
218  c = skipwhitespaces (s);
219  if (inpdotflag && c != ')')
220  s.putback(c);
221  }
222  return s;
223 }
224 
226  friend inline lx_complex operator + (const lx_complex&, const lx_complex&)
227  throw();
229  friend inline lx_complex operator + (const lx_complex&, const lx_real&) throw();
231  friend inline lx_complex operator + (const lx_real&, const lx_complex&) throw();
233  friend inline lx_complex operator + (const lx_complex&, const l_real&) throw();
235  friend inline lx_complex operator + (const l_real&, const lx_complex&) throw();
237  friend inline lx_complex operator + (const lx_complex&, const real&) throw();
239  friend inline lx_complex operator + (const real&, const lx_complex&) throw();
240 
242  friend inline lx_complex operator * (const lx_complex&, const lx_complex&)
243  throw();
244 
246  friend inline lx_complex operator / (const lx_complex&, const lx_complex&)
247  throw();
248 
249 }; // end of class lx_complex
250 
251 // ***********************************************************************
252 // ---------Functions related to type lx_complex -------------------------
253 // ***********************************************************************
254 
255  inline std::ostream& operator << (std::ostream& s, const lx_complex&)
256  throw();
257  inline std::string & operator << (std::string& s, const lx_complex&)
258  throw();
259 
260 // ------- friend functions declared in class lx_complex: -----------
261 
262  inline lx_real Re(const lx_complex&);
263  inline lx_real Im(const lx_complex&);
264  inline int StagPrec(const lx_complex&) throw();
265  inline real expoRe(const lx_complex&) throw();
266  inline real expoIm(const lx_complex&) throw();
267  inline l_real lr_partRe(const lx_complex&) throw();
268  inline l_real lr_partIm(const lx_complex&) throw();
269 
270  inline lx_complex & SetRe(lx_complex&, const lx_real&);
271  inline lx_complex & SetRe(lx_complex&, const l_real&);
272  inline lx_complex & SetRe(lx_complex&, const real&);
273 
274  inline lx_complex & SetIm(lx_complex&, const lx_real&);
275  inline lx_complex & SetIm(lx_complex&, const l_real&);
276  inline lx_complex & SetIm(lx_complex&, const real&);
277 
278  inline lx_complex conj(const lx_complex&) throw();
279 
280  lx_real abs (const lx_complex&) throw();
281  lx_real abs2 (const lx_complex&) throw();
282 
283  inline bool operator == (const lx_complex&, const lx_complex&) throw();
284 
285  inline bool operator == (const lx_complex&, const l_complex&) throw();
286  inline bool operator == (const lx_complex&, const complex&) throw();
287  inline bool operator == (const l_complex&, const lx_complex&) throw();
288  inline bool operator == (const complex&, const lx_complex&) throw();
289 
290  inline bool operator == (const lx_complex&, const lx_real&) throw();
291  inline bool operator == (const lx_complex&, const l_real&) throw();
292  inline bool operator == (const lx_complex&, const real&) throw();
293  inline bool operator == (const lx_real&, const lx_complex&) throw();
294  inline bool operator == (const l_real&, const lx_complex&) throw();
295  inline bool operator == (const real&, const lx_complex&) throw();
296 
297 // ----------------------------------------------------------------------
298 
300  inline bool operator != (const lx_complex&, const lx_complex&) throw();
302  inline bool operator != (const lx_complex&, const l_complex&) throw();
304  inline bool operator != (const lx_complex&, const complex&) throw();
306  inline bool operator != (const l_complex&, const lx_complex&) throw();
308  inline bool operator != (const complex&, const lx_complex&) throw();
309 
311  inline bool operator != (const lx_complex&, const lx_real&) throw();
313  inline bool operator != (const lx_complex&, const l_real&) throw();
315  inline bool operator != (const lx_complex&, const real&) throw();
317  inline bool operator != (const lx_real&, const lx_complex&) throw();
319  inline bool operator != (const l_real&, const lx_complex&) throw();
321  inline bool operator != (const real&, const lx_complex&) throw();
322 
323  inline lx_complex operator - (const lx_complex &) throw();
324 
325 // -------------------------- Output ------------------------------------
326 
327  inline std::ostream& operator << (std::ostream& s, const lx_complex& a)
328  throw(); // A value a of type lx_complex is written to the output channel.
329  inline std::string & operator << (std::string& s, const lx_complex& a)
330  throw();
331  // The value of a variable a of type lx_complex is copied to a string s.
332  // s has the form: { ? , ? }
333 
334 // -------------------------- Input ------------------------------------
335 
337  std::string & operator >> (std::string& s, lx_complex& a) throw();
338 // Writes string s to variable a of type lx_complex;
339 // and returns an empty string s;
340 // Example: s = "{-4000,2}" delivers a value a
341 // with: 10^(-4000)*2 ~ a;
342 
344  void operator >> (const std::string &s, lx_complex &a) throw();
346  void operator >> (const char *s, lx_complex& a) throw();
347 
348 // ---- function and operator declarations outside the class lx_complex ----
349 
351  inline lx_complex operator + (const lx_complex&) throw();
352 
354  inline lx_complex operator + (const lx_complex&, const l_complex&) throw();
356  inline lx_complex operator + (const lx_complex&, const complex&) throw();
358  inline lx_complex operator + (const l_complex&, const lx_complex&) throw();
360  inline lx_complex operator + (const complex&, const lx_complex&) throw();
362  inline lx_complex operator + (const lx_complex&, const lx_real&) throw();
364  inline lx_complex operator + (const lx_real&, const lx_complex&) throw();
366  inline lx_complex operator + (const lx_complex&, const l_real&) throw();
368  inline lx_complex operator + (const l_real&, const lx_complex&) throw();
370  inline lx_complex operator + (const lx_complex&, const real&) throw();
372  inline lx_complex operator + (const real&, const lx_complex&) throw();
373 
375  inline lx_complex & operator +=(lx_complex &, const lx_complex &) throw();
377  inline lx_complex & operator +=(lx_complex &, const l_complex &) throw();
379  inline lx_complex & operator +=(lx_complex &, const complex &) throw();
381  inline lx_complex & operator +=(lx_complex &, const lx_real &) throw();
383  inline lx_complex & operator +=(lx_complex &, const l_real &) throw();
385  inline lx_complex & operator +=(lx_complex &, const real &) throw();
386 
388  inline lx_complex operator - (const lx_complex&, const lx_complex&) throw();
390  inline lx_complex operator - (const lx_complex&, const l_complex&) throw();
392  inline lx_complex operator - (const lx_complex&, const complex&) throw();
394  inline lx_complex operator - (const l_complex&, const lx_complex&) throw();
396  inline lx_complex operator - (const complex&, const lx_complex&) throw();
398  inline lx_complex operator - (const lx_complex&, const lx_real&) throw();
400  inline lx_complex operator - (const lx_complex&, const l_real&) throw();
402  inline lx_complex operator - (const lx_complex&, const real&) throw();
404  inline lx_complex operator - (const lx_real&, const lx_complex&) throw();
406  inline lx_complex operator - (const l_real&, const lx_complex&) throw();
408  inline lx_complex operator - (const real&, const lx_complex&) throw();
409 
411  inline lx_complex & operator -=(lx_complex &, const lx_complex &) throw();
413  inline lx_complex & operator -=(lx_complex &, const l_complex &) throw();
415  inline lx_complex & operator -=(lx_complex &, const complex &) throw();
417  inline lx_complex & operator -=(lx_complex &, const lx_real &) throw();
419  inline lx_complex & operator -=(lx_complex &, const l_real &) throw();
421  inline lx_complex & operator -=(lx_complex &, const real &) throw();
422 
424  inline lx_complex operator * (const lx_complex&, const lx_complex&) throw();
426  inline lx_complex operator * (const lx_complex&, const l_complex&) throw();
428  inline lx_complex operator * (const lx_complex&, const complex&) throw();
430  inline lx_complex operator * (const l_complex&, const lx_complex&) throw();
432  inline lx_complex operator * (const complex&, const lx_complex&) throw();
434  inline lx_complex operator * (const lx_complex&, const lx_real&) throw();
436  inline lx_complex operator * (const lx_complex&, const l_real&) throw();
438  inline lx_complex operator * (const lx_complex&, const real&) throw();
440  inline lx_complex operator * (const lx_real&, const lx_complex&) throw();
442  inline lx_complex operator * (const l_real&, const lx_complex&) throw();
444  inline lx_complex operator * (const real&, const lx_complex&) throw();
445 
447  inline lx_complex & operator *=(lx_complex &, const lx_complex &) throw();
449  inline lx_complex & operator *=(lx_complex &, const l_complex &) throw();
451  inline lx_complex & operator *=(lx_complex &, const complex &) throw();
453  inline lx_complex & operator *=(lx_complex &, const lx_real &) throw();
455  inline lx_complex & operator *=(lx_complex &, const l_real &) throw();
457  inline lx_complex & operator *=(lx_complex &, const real &) throw();
458 
460  inline lx_complex operator / (const lx_complex&, const lx_complex&) throw();
462  inline lx_complex operator / (const lx_complex&, const l_complex&) throw();
464  inline lx_complex operator / (const lx_complex&, const complex&) throw();
466  inline lx_complex operator / (const l_complex&, const lx_complex&) throw();
468  inline lx_complex operator / (const complex&, const lx_complex&) throw();
470  inline lx_complex operator / (const lx_complex&, const lx_real&) throw();
472  inline lx_complex operator / (const lx_complex&, const l_real&) throw();
474  inline lx_complex operator / (const lx_complex&, const real&) throw();
476  inline lx_complex operator / (const lx_real&, const lx_complex&) throw();
478  inline lx_complex operator / (const l_real&, const lx_complex&) throw();
480  inline lx_complex operator / (const real&, const lx_complex&) throw();
481 
483  inline lx_complex & operator /=(lx_complex &, const lx_complex &) throw();
485  inline lx_complex & operator /=(lx_complex &, const l_complex &) throw();
487  inline lx_complex & operator /=(lx_complex &, const complex &) throw();
489  inline lx_complex & operator /=(lx_complex &, const lx_real &) throw();
491  inline lx_complex & operator /=(lx_complex &, const l_real &) throw();
493  inline lx_complex & operator /=(lx_complex &, const real &) throw();
494 
495 
496 
497 // ---------------------------------------------------------------------------
498 // ----- Elementary functions related to lx_complex
499 // ---------------------------------------------------------------------------
500 
502  lx_complex sqr(const lx_complex&) throw();
504  lx_complex sqrt(const lx_complex&) throw();
506  lx_complex sqrt(const lx_complex& ,int) throw();
508  lx_complex exp(const lx_complex&) throw();
510  lx_complex exp2(const lx_complex&) throw();
512  lx_complex exp10(const lx_complex&) throw();
514  lx_complex sin(const lx_complex&) throw();
516  lx_complex cos(const lx_complex&) throw();
518  lx_complex tan(const lx_complex&) throw();
520  lx_complex cot(const lx_complex&) throw();
522  lx_complex asin(const lx_complex&) throw();
524  lx_complex acos(const lx_complex&) throw();
526  lx_complex atan(const lx_complex&) throw();
528  lx_complex acot(const lx_complex&) throw();
530  lx_complex sinh(const lx_complex&) throw();
532  lx_complex cosh(const lx_complex&) throw();
534  lx_complex tanh(const lx_complex&) throw();
536  lx_complex coth(const lx_complex&) throw();
538  lx_complex asinh(const lx_complex&) throw();
540  lx_complex acosh(const lx_complex&) throw();
542  lx_complex atanh(const lx_complex&) throw();
544  lx_complex acoth(const lx_complex&) throw();
546  std::list<lx_complex>sqrt_all(const lx_complex&);
548  lx_real arg(const lx_complex&) throw();
550  lx_real Arg(const lx_complex&) throw();
552  std::list<lx_complex>sqrt_all(const lx_complex&, int);
554  lx_complex ln(const lx_complex&) throw();
556  lx_complex log2(const lx_complex&) throw();
558  lx_complex log10(const lx_complex&) throw();
560  lx_complex power_fast(const lx_complex&, const real&) throw();
562  lx_complex power(const lx_complex&, const real&) throw();
564  lx_complex pow(const lx_complex&, const lx_real&) throw();
566  lx_complex pow(const lx_complex&, const lx_complex&) throw();
567 
569  lx_complex sqrt1px2(const lx_complex&) throw();
571  lx_complex sqrt1mx2(const lx_complex&) throw();
573  lx_complex sqrtx2m1(const lx_complex&) throw();
575  lx_complex sqrtp1m1(const lx_complex&) throw();
577  lx_complex expm1(const lx_complex&) throw();
579  lx_complex lnp1(const lx_complex&) throw();
580 
581 } // end namespace cxsc
582 
583 #include "lx_complex.inl"
584 
585 #endif // _CXSC_LX_COMPLEX_HPP_INCLUDED
cinterval sqrtx2m1(const cinterval &z)
Calculates .
Definition: cimath.cpp:1109
cinterval sqrt1px2(const cinterval &z)
Calculates .
Definition: cimath.cpp:1071
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
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
cinterval tanh(const cinterval &z)
Calculates .
Definition: cimath.cpp:565
cinterval asinh(const cinterval &z)
Calculates .
Definition: cimath.cpp:2718
cinterval log10(const cinterval &z)
Calculates .
Definition: cimath.cpp:903
cinterval sqrt1mx2(const cinterval &z)
Calculates .
Definition: cimath.cpp:1140
cinterval lnp1(const cinterval &z)
Calculates .
Definition: cimath.cpp:867
std::list< cinterval > sqrt_all(const cinterval &z)
Calculates and returns all possible solutions.
Definition: cimath.cpp:1176
cinterval sqrt(const cinterval &z)
Calculates .
Definition: cimath.cpp:1007
cinterval cos(const cinterval &z)
Calculates .
Definition: cimath.cpp:207
cinterval atanh(const cinterval &z)
Calculates .
Definition: cimath.cpp:3317
cinterval power_fast(const cinterval &z, int n)
Calculates .
Definition: cimath.cpp:1520
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
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
cinterval acoth(const cinterval &z)
Calculates .
Definition: cimath.cpp:3330
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
cinterval power(const cinterval &z, int n)
Calculates .
Definition: cimath.cpp:1941
ivector abs(const cimatrix_subv &mv)
Returns the absolute value of the matrix.
Definition: cimatrix.inl:737
cinterval acosh(const cinterval &z)
Calculates .
Definition: cimath.cpp:2732