C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
lx_complex.hpp
00001 /*
00002 **  CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
00003 **
00004 **  Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
00005 **                          Universitaet Karlsruhe, Germany
00006 **            (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
00007 **                          Universitaet Wuppertal, Germany   
00008 **
00009 **  This library is free software; you can redistribute it and/or
00010 **  modify it under the terms of the GNU Library General Public
00011 **  License as published by the Free Software Foundation; either
00012 **  version 2 of the License, or (at your option) any later version.
00013 **
00014 **  This library is distributed in the hope that it will be useful,
00015 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 **  Library General Public License for more details.
00018 **
00019 **  You should have received a copy of the GNU Library General Public
00020 **  License along with this library; if not, write to the Free
00021 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 /* CVS $Id: lx_complex.hpp,v 1.9 2014/01/30 17:23:47 cxsc Exp $ */
00025 
00026 
00027 /*
00028 **  F. Blomquist, University of Wuppertal, 19.09.2007;
00029 */
00030 
00031 /*
00032 **  Implementation of the classes
00033 **
00034 **  lx_complex    with all tools and elementary functions for complex
00035 **                point and interval aruments
00036 **
00037 */
00038 
00039 #ifndef _CXSC_LX_COMPLEX_HPP_INCLUDED
00040 #define _CXSC_LX_COMPLEX_HPP_INCLUDED
00041 
00042 #include <iostream>
00043 #include <except.hpp>
00044 #include <l_cinterval.hpp>
00045 #include <l_complex.hpp>
00046 #include "lx_interval.hpp"
00047 
00048 namespace cxsc {
00049 // --------------------------------------------------------------------------
00050 //      Class lx_complex
00051 // --------------------------------------------------------------------------
00052          
00053         class lx_complex
00054         {
00055                 private:
00056     // ------------- Data Elements -------------------------------------------
00057                         lx_real re;
00058                         lx_real im;
00059 
00060                 public:
00061     // ------------- Constructors --------------------------------------------
00062 
00064                         lx_complex(void)  throw() {}
00066                         lx_complex(const real& nr, const l_real &ar, const real& ni, const l_real &ai)
00067                                         throw() : re(lx_real(nr,ar)), im(lx_real(ni,ai))  { }
00069                         lx_complex(const real& n, const real &a) 
00070                                         throw() : re(lx_real(n,a)), im(lx_real(0.0)) { }
00072                         lx_complex(const lx_real &a, const lx_real &b)
00073                                         throw() : re(a), im(b) { }
00075                         lx_complex(const lx_real &a) throw() : re(a), im(lx_real(0.0)) { }
00077                         explicit lx_complex(const l_real &a, const l_real &b) 
00078                                         throw() : re(a), im(b) { }
00080                         explicit lx_complex(const l_real &a) 
00081                                         throw() : re(a), im(lx_real(0.0)) { }
00083                         explicit lx_complex(const real &a) 
00084                                         throw() : re(a), im(lx_real(0.0)) { }
00086                         explicit lx_complex(const complex &a) 
00087                                         throw() : re(Re(a)), im(Im(a)) { }
00089                         explicit lx_complex(const l_complex &a) 
00090                                         throw() : re(lx_real(0,Re(a))), im(lx_real(0,Im(a))) { }
00092                         lx_complex(const real& pr, const string& sr,
00093                                                   const real& pi, const string& si)
00094                                         throw() : re(lx_real(pr,sr)), im(lx_real(pi,si)) { }
00095 
00096 // ------------- Assignments ---------------------------------------------
00098                         lx_complex & operator = (const lx_real & lr) throw() 
00099                         { re = lr; im = 0; return *this; }
00101                         lx_complex & operator = (const l_real & lr) throw() 
00102                         { re = lr; im = 0; return *this; }
00104                         lx_complex & operator = (const real & lr) throw() 
00105                         { re = lr; im = 0; return *this; }
00107                         lx_complex & operator = (const l_complex & c) throw() 
00108                         { re = Re(c); im = Im(c); return *this; }
00110                         lx_complex & operator = (const complex & c) throw() 
00111                         { re = Re(c); im = Im(c); return *this; } 
00112     
00113     // ------------- Functions -----------------------------------------------
00114 
00116                         friend inline lx_real Re(const lx_complex&);
00118                         friend inline lx_real Im(const lx_complex&);
00120                         friend inline int StagPrec(const lx_complex&) throw();
00122                         friend inline real expoRe(const lx_complex&) throw();
00124                         friend inline real expoIm(const lx_complex&) throw();
00126                         friend inline l_real lr_partRe(const lx_complex&) throw();
00128                         friend inline l_real lr_partIm(const lx_complex&) throw();
00129 
00131                         friend inline lx_complex & SetRe(lx_complex&, const lx_real&);
00133                         friend inline lx_complex & SetRe(lx_complex&, const l_real&);
00135                         friend inline lx_complex & SetRe(lx_complex&, const real&);
00136 
00138                         friend inline lx_complex & SetIm(lx_complex&, const lx_real&);
00140                         friend inline lx_complex & SetIm(lx_complex&, const l_real&);
00142                         friend inline lx_complex & SetIm(lx_complex&, const real&);
00143          
00145                         friend inline lx_complex conj(const lx_complex& a) throw();
00147                         friend lx_real abs  (const lx_complex&) throw();
00149                         friend lx_real abs2 (const lx_complex&) throw();
00150          
00152                         friend inline bool operator ! (const lx_complex& ) throw();
00153          
00155                         friend inline bool operator == (const lx_complex&, const lx_complex&) 
00156                                         throw();
00158                         friend inline bool operator == (const lx_complex&, const l_complex&) 
00159                                         throw();
00161                         friend inline bool operator == (const lx_complex&, const complex&) 
00162                                         throw();
00164                         friend inline bool operator == (const l_complex&, const lx_complex&) 
00165                                         throw();
00167                         friend inline bool operator == (const complex&,   const lx_complex&) 
00168                                         throw();
00170                         friend inline bool operator == (const lx_complex&, const lx_real&) throw();
00172                         friend inline bool operator == (const lx_complex&, const l_real&) throw();
00174                         friend inline bool operator == (const lx_complex&, const real&)   throw();
00176                         friend inline bool operator == (const lx_real&, const lx_complex&) throw();
00178                         friend inline bool operator == (const l_real&, const lx_complex&) throw();
00180                         friend inline bool operator == (const real&,   const lx_complex&) throw();
00181 
00183                         friend inline lx_complex operator - (const lx_complex &) throw();
00184          
00185 
00186 // ----------------------- Output --------------------------------------------
00187          
00189                         friend inline std::ostream& operator << (std::ostream& s, const lx_complex& a) 
00190                                         throw(); // A value a of type lx_complex is written to the output channel.
00192                         friend inline std::string & operator << (std::string &s, const lx_complex& a) 
00193                                         throw();
00194 // The value of a variable a of type lx_complex is copied to a string s.
00195 // s has the form:  ({2**()*...} , {2**()*...})
00196 
00197 // ----------------------- Input --------------------------------------------
00198 
00200                         friend std::string & operator >> (std::string& s, lx_complex& a) throw();
00201 
00203 friend std::istream & operator >> (std::istream &s, lx_complex &a) throw()
00204 // An input of a complex number z of the form ({...,...},{...,...}) is
00205 // copied to the variable a of type lx_complex.
00206 {
00207         char c;
00208         std::cout << "Real part: {Exponent to base 10, real number} = ?" 
00209                         << std::endl;
00210         s >> a.re;
00211         std::cout << "Img. part: {Exponent to base 10, real number} = ?" 
00212                         << std::endl;   
00213         s >> a.im >> RestoreOpt;
00214 
00215         if (!waseolnflag) 
00216         {
00217                 skipeolnflag = false, inpdotflag = true;
00218                 c = skipwhitespaces (s);
00219                 if (inpdotflag && c != ')') 
00220                         s.putback(c);
00221         }
00222         return s;
00223 }
00224 
00226                         friend inline lx_complex operator + (const lx_complex&, const lx_complex&)
00227                                         throw();
00229                         friend inline lx_complex operator + (const lx_complex&, const lx_real&) throw();
00231                         friend inline lx_complex operator + (const lx_real&, const lx_complex&) throw();
00233                         friend inline lx_complex operator + (const lx_complex&, const l_real&) throw();
00235                         friend inline lx_complex operator + (const l_real&, const lx_complex&) throw();
00237                         friend inline lx_complex operator + (const lx_complex&, const real&) throw();
00239                         friend inline lx_complex operator + (const real&, const lx_complex&) throw();
00240 
00242                         friend inline lx_complex operator * (const lx_complex&, const lx_complex&)
00243                                         throw();
00244                 
00246                         friend inline lx_complex operator / (const lx_complex&, const lx_complex&)
00247                                         throw();
00248 
00249 }; // end of class lx_complex
00250 
00251 // ***********************************************************************
00252 // ---------Functions related to type lx_complex -------------------------
00253 // ***********************************************************************
00254 
00255     inline std::ostream& operator << (std::ostream& s, const lx_complex&) 
00256                          throw();
00257          inline std::string & operator << (std::string&  s, const lx_complex&) 
00258                          throw(); 
00259          
00260 // ------- friend functions declared in class lx_complex: -----------
00261 
00262          inline lx_real Re(const lx_complex&);
00263          inline lx_real Im(const lx_complex&);
00264          inline int StagPrec(const lx_complex&) throw();
00265          inline real expoRe(const lx_complex&) throw();
00266          inline real expoIm(const lx_complex&) throw();
00267          inline l_real lr_partRe(const lx_complex&) throw();
00268          inline l_real lr_partIm(const lx_complex&) throw();
00269 
00270          inline lx_complex & SetRe(lx_complex&, const lx_real&);
00271          inline lx_complex & SetRe(lx_complex&, const l_real&);
00272          inline lx_complex & SetRe(lx_complex&, const real&);
00273 
00274          inline lx_complex & SetIm(lx_complex&, const lx_real&);
00275          inline lx_complex & SetIm(lx_complex&, const l_real&);
00276          inline lx_complex & SetIm(lx_complex&, const real&);
00277          
00278          inline lx_complex conj(const lx_complex&) throw();
00279          
00280          lx_real abs  (const lx_complex&) throw();
00281          lx_real abs2 (const lx_complex&) throw();
00282 
00283          inline bool operator == (const lx_complex&, const lx_complex&) throw();
00284 
00285          inline bool operator == (const lx_complex&, const l_complex&) throw();
00286          inline bool operator == (const lx_complex&, const complex&) throw();
00287          inline bool operator == (const l_complex&, const lx_complex&) throw();
00288          inline bool operator == (const complex&,   const lx_complex&) throw();
00289 
00290          inline bool operator == (const lx_complex&, const lx_real&) throw();
00291          inline bool operator == (const lx_complex&, const l_real&) throw();
00292          inline bool operator == (const lx_complex&, const real&)   throw();
00293          inline bool operator == (const lx_real&, const lx_complex&) throw();
00294          inline bool operator == (const l_real&, const lx_complex&) throw();
00295          inline bool operator == (const real&,   const lx_complex&) throw();
00296 
00297 // ----------------------------------------------------------------------
00298          
00300          inline bool operator != (const lx_complex&, const lx_complex&) throw();
00302          inline bool operator != (const lx_complex&, const l_complex&) throw();
00304          inline bool operator != (const lx_complex&, const complex&) throw();
00306          inline bool operator != (const l_complex&, const lx_complex&) throw();
00308          inline bool operator != (const complex&,   const lx_complex&) throw();
00309 
00311          inline bool operator != (const lx_complex&, const lx_real&) throw();
00313          inline bool operator != (const lx_complex&, const l_real&) throw();
00315          inline bool operator != (const lx_complex&, const real&)   throw();
00317          inline bool operator != (const lx_real&, const lx_complex&) throw();
00319          inline bool operator != (const l_real&, const lx_complex&) throw();
00321          inline bool operator != (const real&,   const lx_complex&) throw();
00322 
00323          inline lx_complex operator - (const lx_complex &) throw();
00324 
00325 // -------------------------- Output ------------------------------------
00326 
00327          inline std::ostream& operator << (std::ostream& s, const lx_complex& a) 
00328                          throw(); // A value a of type lx_complex is written to the output channel.
00329          inline std::string & operator << (std::string& s, const lx_complex& a) 
00330                          throw();
00331     // The value of a variable a of type lx_complex is copied to a string s.
00332     // s has the form:  { ? , ? }
00333          
00334 // -------------------------- Input ------------------------------------
00335          
00337          std::string & operator >> (std::string& s, lx_complex& a) throw();
00338 // Writes string s to variable a of type lx_complex;
00339 // and returns an empty string s;
00340 // Example:  s = "{-4000,2}" delivers a value a
00341 // with:    10^(-4000)*2 ~ a;
00342         
00344          void operator >> (const std::string &s, lx_complex &a) throw();
00346          void operator >> (const char *s, lx_complex& a) throw();
00347 
00348 // ---- function and operator declarations outside the class lx_complex ----
00349         
00351          inline lx_complex operator + (const lx_complex&) throw();
00352 
00354          inline lx_complex operator + (const lx_complex&, const l_complex&) throw();
00356          inline lx_complex operator + (const lx_complex&, const complex&) throw();
00358          inline lx_complex operator + (const l_complex&, const lx_complex&) throw();
00360          inline lx_complex operator + (const complex&, const lx_complex&) throw();
00362          inline lx_complex operator + (const lx_complex&, const lx_real&) throw();
00364          inline lx_complex operator + (const lx_real&, const lx_complex&) throw();
00366          inline lx_complex operator + (const lx_complex&, const l_real&) throw();
00368          inline lx_complex operator + (const l_real&, const lx_complex&) throw();
00370          inline lx_complex operator + (const lx_complex&, const real&) throw();
00372          inline lx_complex operator + (const real&, const lx_complex&) throw();
00373          
00375          inline lx_complex & operator +=(lx_complex &, const lx_complex &) throw();
00377          inline lx_complex & operator +=(lx_complex &, const l_complex &) throw();
00379          inline lx_complex & operator +=(lx_complex &, const complex &) throw();
00381          inline lx_complex & operator +=(lx_complex &, const lx_real &) throw();
00383          inline lx_complex & operator +=(lx_complex &, const l_real &) throw();
00385          inline lx_complex & operator +=(lx_complex &, const real &) throw();
00386          
00388          inline lx_complex operator - (const lx_complex&, const lx_complex&) throw();
00390          inline lx_complex operator - (const lx_complex&, const l_complex&) throw();
00392          inline lx_complex operator - (const lx_complex&, const complex&) throw();
00394          inline lx_complex operator - (const l_complex&, const lx_complex&) throw();
00396          inline lx_complex operator - (const complex&, const lx_complex&) throw();
00398          inline lx_complex operator - (const lx_complex&, const lx_real&) throw();
00400          inline lx_complex operator - (const lx_complex&, const l_real&) throw();
00402          inline lx_complex operator - (const lx_complex&, const real&) throw();
00404          inline lx_complex operator - (const lx_real&, const lx_complex&) throw();
00406          inline lx_complex operator - (const l_real&, const lx_complex&) throw();
00408          inline lx_complex operator - (const real&, const lx_complex&) throw();
00409          
00411          inline lx_complex & operator -=(lx_complex &, const lx_complex &) throw();
00413          inline lx_complex & operator -=(lx_complex &, const l_complex &) throw();
00415          inline lx_complex & operator -=(lx_complex &, const complex &) throw();
00417          inline lx_complex & operator -=(lx_complex &, const lx_real &) throw();
00419          inline lx_complex & operator -=(lx_complex &, const l_real &) throw();
00421          inline lx_complex & operator -=(lx_complex &, const real &) throw();
00422          
00424          inline lx_complex operator * (const lx_complex&, const lx_complex&) throw();
00426          inline lx_complex operator * (const lx_complex&, const l_complex&) throw();
00428          inline lx_complex operator * (const lx_complex&, const complex&) throw();
00430          inline lx_complex operator * (const l_complex&, const lx_complex&) throw();
00432          inline lx_complex operator * (const complex&,   const lx_complex&) throw();
00434          inline lx_complex operator * (const lx_complex&, const lx_real&) throw();
00436          inline lx_complex operator * (const lx_complex&, const l_real&) throw();
00438          inline lx_complex operator * (const lx_complex&, const real&) throw();
00440          inline lx_complex operator * (const lx_real&, const lx_complex&) throw();
00442          inline lx_complex operator * (const l_real&,  const lx_complex&) throw();
00444          inline lx_complex operator * (const real&,    const lx_complex&) throw();
00445          
00447          inline lx_complex & operator *=(lx_complex &, const lx_complex &) throw();
00449          inline lx_complex & operator *=(lx_complex &, const l_complex &) throw();
00451          inline lx_complex & operator *=(lx_complex &, const complex &) throw();
00453          inline lx_complex & operator *=(lx_complex &, const lx_real &) throw();
00455          inline lx_complex & operator *=(lx_complex &, const l_real &) throw();
00457          inline lx_complex & operator *=(lx_complex &, const real &) throw();
00458          
00460          inline lx_complex operator / (const lx_complex&, const lx_complex&) throw();
00462          inline lx_complex operator / (const lx_complex&, const l_complex&) throw();
00464          inline lx_complex operator / (const lx_complex&, const complex&) throw();
00466          inline lx_complex operator / (const l_complex&, const lx_complex&) throw();
00468          inline lx_complex operator / (const complex&,   const lx_complex&) throw();
00470          inline lx_complex operator / (const lx_complex&, const lx_real&) throw();
00472          inline lx_complex operator / (const lx_complex&, const l_real&) throw();
00474          inline lx_complex operator / (const lx_complex&, const real&) throw();
00476          inline lx_complex operator / (const lx_real&, const lx_complex&) throw();
00478          inline lx_complex operator / (const l_real&,  const lx_complex&) throw();
00480          inline lx_complex operator / (const real&,    const lx_complex&) throw();
00481          
00483          inline lx_complex & operator /=(lx_complex &, const lx_complex &) throw();
00485          inline lx_complex & operator /=(lx_complex &, const l_complex &) throw();
00487          inline lx_complex & operator /=(lx_complex &, const complex &) throw();
00489          inline lx_complex & operator /=(lx_complex &, const lx_real &) throw();
00491          inline lx_complex & operator /=(lx_complex &, const l_real &) throw();
00493          inline lx_complex & operator /=(lx_complex &, const real &) throw();
00494 
00495 
00496          
00497 // ---------------------------------------------------------------------------
00498 // ----- Elementary functions related to lx_complex
00499 // ---------------------------------------------------------------------------
00500 
00502          lx_complex sqr(const lx_complex&) throw();
00504          lx_complex sqrt(const lx_complex&) throw();
00506          lx_complex sqrt(const lx_complex& ,int) throw();
00508          lx_complex exp(const lx_complex&) throw();
00510          lx_complex exp2(const lx_complex&) throw();
00512          lx_complex exp10(const lx_complex&) throw();
00514          lx_complex sin(const lx_complex&) throw();
00516          lx_complex cos(const lx_complex&) throw();
00518          lx_complex tan(const lx_complex&) throw();
00520          lx_complex cot(const lx_complex&) throw();
00522          lx_complex asin(const lx_complex&) throw();
00524          lx_complex acos(const lx_complex&) throw();
00526          lx_complex atan(const lx_complex&) throw();
00528          lx_complex acot(const lx_complex&) throw();
00530          lx_complex sinh(const lx_complex&) throw();
00532          lx_complex cosh(const lx_complex&) throw();
00534          lx_complex tanh(const lx_complex&) throw();
00536          lx_complex coth(const lx_complex&) throw();
00538          lx_complex asinh(const lx_complex&) throw();
00540          lx_complex acosh(const lx_complex&) throw();
00542          lx_complex atanh(const lx_complex&) throw();
00544          lx_complex acoth(const lx_complex&) throw();
00546          std::list<lx_complex>sqrt_all(const lx_complex&);
00548          lx_real arg(const lx_complex&) throw();
00550          lx_real Arg(const lx_complex&) throw();
00552          std::list<lx_complex>sqrt_all(const lx_complex&, int);
00554          lx_complex ln(const lx_complex&) throw();
00556          lx_complex log2(const lx_complex&) throw();
00558          lx_complex log10(const lx_complex&) throw();
00560          lx_complex power_fast(const lx_complex&, const real&) throw();
00562          lx_complex power(const lx_complex&, const real&) throw();
00564          lx_complex pow(const lx_complex&, const lx_real&) throw();
00566          lx_complex pow(const lx_complex&, const lx_complex&) throw();
00567 
00569          lx_complex sqrt1px2(const lx_complex&) throw();
00571          lx_complex sqrt1mx2(const lx_complex&) throw();
00573          lx_complex sqrtx2m1(const lx_complex&) throw();
00575          lx_complex sqrtp1m1(const lx_complex&) throw();
00577          lx_complex expm1(const lx_complex&) throw();
00579          lx_complex lnp1(const lx_complex&) throw();
00580 
00581 }  // end namespace cxsc
00582 
00583 #include "lx_complex.inl"
00584 
00585 #endif // _CXSC_LX_COMPLEX_HPP_INCLUDED