00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _CXSC_COMPLEX_HPP_INCLUDED
00027 #define _CXSC_COMPLEX_HPP_INCLUDED
00028
00029 #include <iostream>
00030 #include <string>
00031 #include <list>
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
00053 real re;
00054 real im;
00055
00056 public:
00057
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
00067
00069 explicit inline complex(const real &r) throw() : re(r),im(0.0) { }
00070
00071
00072
00073
00074
00075
00076
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
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
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
00230
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
00257 friend inline real & Re(complex & a);
00259 friend inline real Re(const complex & a);
00261 friend inline real & Im(complex & a);
00263 friend inline real Im(const complex & a);
00264
00266 friend inline complex & SetRe(complex & a,const real & b);
00268 friend inline complex & SetIm(complex & a,const real & b);
00269
00271 friend real abs(complex) throw();
00273 friend real abs2(const complex &) throw();
00275 friend inline complex conj(const complex &) throw();
00276
00277
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();
00338 complex & operator = (const l_complex&) throw();
00339 };
00340
00341
00342
00343
00344
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
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 }
00470
00471
00472 #include "complex.inl"
00473
00474 #endif
00475