C-XSC - A C++ Class Library for Extended Scientific Computing
2.5.4
|
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: complex.hpp,v 1.32 2014/01/30 17:23:44 cxsc Exp $ */ 00025 00026 #ifndef _CXSC_COMPLEX_HPP_INCLUDED 00027 #define _CXSC_COMPLEX_HPP_INCLUDED 00028 00029 #include <iostream> 00030 #include <string> 00031 #include <list> // Blomquist, 02.12.2008; 00032 #include "compiler.h" 00033 #include "except.hpp" 00034 #include "real.hpp" 00035 00036 namespace cxsc { 00037 00038 class cvector; 00039 class cmatrix; 00040 class cvector_slice; 00041 class cmatrix_slice; 00042 00043 00045 00049 class complex 00050 { 00051 private: 00052 // ---- Datenelemente --------------------------------------- 00053 real re; 00054 real im; 00055 00056 public: 00057 // ---- Constructors --------------------------------------- 00059 complex(void) throw () {} 00061 complex(const real & a,const real & b) throw () : re(a), im(b) { } 00062 00064 inline complex & operator= (const real & r) throw(); 00065 00066 // ---- Type-Casts --------------------------------------- 00067 00069 explicit inline complex(const real &r) throw() : re(r),im(0.0) { } 00070 00071 00072 // friend inline complex _complex(const real &a) throw () { return complex(a,0.0); } 00073 // friend inline complex _complex(const real &a,const real &b) throw(){ return complex(a,b); } 00074 00075 00076 // The following are defined in the specific vector, matrix-files 00077 #if(CXSC_INDEX_CHECK) 00078 00079 explicit INLINE complex(const cvector &) throw (ERROR_CVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_CVECTOR_USE_OF_UNINITIALIZED_OBJ); 00081 explicit INLINE complex(const cvector_slice &) throw (ERROR_CVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_CVECTOR_USE_OF_UNINITIALIZED_OBJ); 00083 explicit INLINE complex(const cmatrix &) throw (ERROR_CMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_CMATRIX_USE_OF_UNINITIALIZED_OBJ); 00085 explicit INLINE complex(const cmatrix_slice &) throw (ERROR_CMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_CMATRIX_USE_OF_UNINITIALIZED_OBJ); 00087 00092 friend INLINE complex _complex(const cvector &) throw (ERROR_CVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_CVECTOR_USE_OF_UNINITIALIZED_OBJ); 00094 00099 friend INLINE complex _complex(const cvector_slice &) throw (ERROR_CVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_CVECTOR_USE_OF_UNINITIALIZED_OBJ); 00101 00106 friend INLINE complex _complex(const cmatrix &) throw (ERROR_CMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_CMATRIX_USE_OF_UNINITIALIZED_OBJ); 00108 00113 friend INLINE complex _complex(const cmatrix_slice &) throw (ERROR_CMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_CMATRIX_USE_OF_UNINITIALIZED_OBJ); 00114 #else 00115 00116 explicit INLINE complex(const cvector &) throw (); 00118 explicit INLINE complex(const cvector_slice &) throw (); 00120 explicit INLINE complex(const cmatrix &) throw (); 00122 explicit INLINE complex(const cmatrix_slice &) throw (); 00124 00129 friend INLINE complex _complex(const cvector &) throw (); 00131 00136 friend INLINE complex _complex(const cvector_slice &) throw (); 00138 00143 friend INLINE complex _complex(const cmatrix &) throw (); 00145 00150 friend INLINE complex _complex(const cmatrix_slice &) throw (); 00151 #endif 00152 00153 explicit complex(const cdotprecision &) throw(); 00155 00160 friend inline complex _complex(const cdotprecision &a) throw() { return complex(a); } 00161 00163 complex & operator =(const cdotprecision &) throw(); 00164 00165 // ---- Input/Output --------------------------------------- 00167 friend std::ostream & operator <<(std::ostream &,const complex &) throw(); 00169 friend std::istream & operator >>(std::istream &,complex &) throw(); 00171 friend std::string & operator <<(std::string &,const complex &) throw(); 00173 friend std::string & operator >>(std::string &,complex &) throw(); 00175 friend void operator >>(const char *,complex &) throw(); 00177 friend void operator >>(const std::string &,complex &) throw(); 00178 00179 // ---- Std.Operators --------------------------------------- 00181 friend inline complex operator -(const complex &) throw (); 00183 friend inline complex operator +(const complex &) throw (); 00184 00186 friend inline complex operator +(const complex &,const complex &) throw(); 00188 friend inline complex operator -(const complex &,const complex &) throw(); 00190 friend complex operator *(const complex &,const complex &) throw(); 00192 friend complex operator /(const complex &,const complex &) throw(); 00193 00195 friend inline complex & operator +=(complex &, const complex &) throw(); 00197 friend inline complex & operator -=(complex &, const complex &) throw(); 00199 friend inline complex & operator *=(complex &, const complex &) throw(); 00201 friend inline complex & operator /=(complex &, const complex &) throw(); 00202 00204 friend inline complex operator +(const complex &,const real &) throw(); 00206 friend inline complex operator +(const real &,const complex &) throw(); 00208 friend inline complex operator -(const complex &,const real &) throw(); 00210 friend inline complex operator -(const real &,const complex &) throw(); 00212 friend inline complex operator *(const complex &,const real &) throw(); 00214 friend inline complex operator *(const real &,const complex &) throw(); 00216 friend inline complex operator /(const complex &,const real &) throw(); 00218 friend inline complex operator /(const real &,const complex &) throw(); 00219 00221 friend inline complex & operator +=(complex &, const real &) throw(); 00223 friend inline complex & operator -=(complex &, const real &) throw(); 00225 friend inline complex & operator *=(complex &, const real &) throw(); 00227 friend inline complex & operator /=(complex &, const real &) throw(); 00228 00229 // ---- Comp.Operat. --------------------------------------- 00230 // inline operator void *() const throw() { if(re) return (void *)1; if(im) return (void *)1; else return 0; } 00232 friend inline bool operator! (const complex & a) throw(); 00234 friend inline bool operator== (const complex & a, const complex & b) throw(); 00236 friend inline bool operator!= (const complex & a, const complex & b) throw(); 00238 friend inline bool operator== (const complex & a, const real & b) throw(); 00240 friend inline bool operator== (const real & a, const complex & b) throw(); 00242 friend inline bool operator!= (const complex & a, const real & b) throw(); 00244 friend inline bool operator!= (const real & a, const complex & b) throw(); 00245 00247 friend bool operator== (const complex & a, const dotprecision & b) throw(); 00249 friend bool operator== (const dotprecision & a, const complex & b) throw(); 00251 friend bool operator!= (const complex & a, const dotprecision & b) throw(); 00253 friend bool operator!= (const dotprecision & a, const complex & b) throw(); 00254 00255 // ---- Others ------------------------------------------- 00257 friend inline real & Re(complex & a); // { return a.re; } 00259 friend inline real Re(const complex & a); // { return a.re; } 00261 friend inline real & Im(complex & a); // { return a.im; } 00263 friend inline real Im(const complex & a); // { return a.im; } 00264 00266 friend inline complex & SetRe(complex & a,const real & b); // { a.re=b; return a; } 00268 friend inline complex & SetIm(complex & a,const real & b); // { a.im=b; return a; } 00269 00271 friend real abs(complex) throw(); 00273 friend real abs2(const complex &) throw(); 00275 friend inline complex conj(const complex &) throw(); 00276 00277 // -------------- Directed rounding, Blomquist 07.11.02 -------------------- 00278 00280 friend complex divn (const complex &, const complex &); 00282 friend complex divd (const complex &, const complex &); 00284 friend complex divu (const complex &, const complex &); 00286 friend inline complex divd(const complex &, const real &) throw(); 00288 friend inline complex divu(const complex &, const real &) throw(); 00290 friend inline complex divd(const real &, const complex &) throw(); 00292 friend inline complex divu(const real &, const complex &) throw(); 00293 00295 friend complex muld (const complex &, const complex &) throw(); 00297 friend complex mulu (const complex &, const complex &) throw(); 00299 friend inline complex muld(const complex &, const real &) throw(); 00301 friend inline complex mulu(const complex &, const real &) throw(); 00303 friend inline complex muld(const real &, const complex &) throw(); 00305 friend inline complex mulu(const real &, const complex &) throw(); 00306 00307 00309 friend inline complex addd(const complex &, const complex &) throw(); 00311 friend inline complex addu(const complex &, const complex &) throw(); 00313 friend inline complex addd(const complex &, const real &) throw(); 00315 friend inline complex addu(const complex &, const real &) throw(); 00317 friend inline complex addd(const real &, const complex &) throw(); 00319 friend inline complex addu(const real &, const complex &) throw(); 00320 00321 00323 friend inline complex subd(const complex &, const complex &) throw(); 00325 friend inline complex subu(const complex &, const complex &) throw(); 00327 friend inline complex subd(const complex &, const real &) throw(); 00329 friend inline complex subu(const complex &, const real &) throw(); 00331 friend inline complex subd(const real &, const complex &) throw(); 00333 friend inline complex subu(const real &, const complex &) throw(); 00334 00336 complex & operator = (const lx_complex&) throw(); // Blomquist, 12.11.2008; 00338 complex & operator = (const l_complex&) throw(); // Blomquist, 12.11.2008; 00339 }; // end class complex 00340 00341 00342 // --------------------------------------------------------------------------- 00343 // ---- ---- 00344 // ---- friend functions of class real (not inline) ---- 00345 // ---- ---- 00346 // --------------------------------------------------------------------------- 00347 00348 complex divn (const complex &, const complex &); 00349 complex divd (const complex &, const complex &); 00350 complex divu (const complex &, const complex &); 00351 complex muld (const complex &, const complex &) throw(); 00352 complex mulu (const complex &, const complex &) throw(); 00353 00354 // --------------------------------------------------------------------------- 00355 // ---- ---- 00356 // ---- global functions associated with class real ---- 00357 // ---- ---- 00358 // --------------------------------------------------------------------------- 00359 00361 00366 inline complex _complex(const real &a) throw () { return complex(a,0.0); } 00368 00373 inline complex _complex(const real &a,const real &b) throw(){ return complex(a,b); } 00374 00376 inline real & Re(complex & z) { return z.re; } 00378 inline real Re(const complex & z) { return z.re; } 00380 inline real & Im(complex & z) { return z.im; } 00382 inline real Im(const complex & z) { return z.im; } 00383 00385 inline complex & SetRe(complex & z,const real & b) { z.re=b; return z; } 00387 inline complex & SetIm(complex & z,const real & b) { z.im=b; return z; } 00388 00390 inline complex sqr (const complex&) throw(); 00392 complex sqrt(const complex&) throw(); 00394 complex sqrtp1m1(const complex&) throw(); 00396 complex sqrt1px2(const complex&) throw(); 00398 complex sqrtx2m1(const complex&) throw(); 00400 complex sqrt1mx2(const complex&) throw(); 00401 00403 complex exp(const complex&) throw(); 00405 complex expm1(const complex&) throw(); 00407 complex exp2(const complex&) throw(); 00409 complex exp10(const complex&) throw(); 00411 complex sin(const complex&) throw(); 00413 complex cos(const complex&) throw(); 00415 complex tan(const complex&) throw(); 00417 complex cot(const complex&) throw(); 00419 complex asin(const complex&) throw(); 00421 complex acos(const complex&) throw(); 00423 complex atan(const complex&) throw(); 00425 complex acot(const complex&) throw(); 00427 complex sinh(const complex&) throw(); 00429 complex cosh(const complex&) throw(); 00431 complex tanh(const complex&) throw(); 00433 complex coth(const complex&) throw(); 00435 complex asinh(const complex&) throw(); 00437 complex acosh(const complex&) throw(); 00439 complex atanh(const complex&) throw(); 00441 complex acoth(const complex&) throw(); 00443 std::list<complex>sqrt_all(const complex&); 00445 complex sqrt(const complex&, int) throw(); 00447 real arg(const complex&) throw(); 00449 real Arg(const complex&) throw(); 00451 std::list<complex>sqrt_all(const complex&, int); 00453 complex ln(const complex&) throw(); 00455 complex lnp1(const complex&) throw(); 00457 complex log2(const complex&) throw(); 00459 complex log10(const complex&) throw(); 00461 complex power(const complex&,int) throw(); 00463 complex power_fast(const complex&, int) throw(); 00465 complex pow(const complex&, const real&) throw(); 00467 complex pow(const complex&, const complex&) throw(); 00468 00469 } // namespace cxsc 00470 00471 00472 #include "complex.inl" 00473 00474 #endif 00475