C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
cdot.inl
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: cdot.inl,v 1.31 2014/01/30 17:23:43 cxsc Exp $ */
00025 
00026 namespace cxsc {
00027 
00028 // ---- Konstruktoren ----
00029 
00030 inline cdotprecision::cdotprecision(const dotprecision &a,const dotprecision &b)
00031                         : re(a), im(b), k(0) { re.set_k(0); im.set_k(0); }
00032 
00033 inline cdotprecision::cdotprecision(const real &a,const real &b)
00034                         : re(a), im(b), k(0) {}
00035 
00036 inline cdotprecision::cdotprecision(const cdotprecision &a)
00037                         : re(a.re), im(a.im), k(a.k) {}
00038 
00039 inline cdotprecision::cdotprecision(const l_real &a, const l_real &b)
00040                         : re(a), im(b), k(0) {}
00041 
00042 inline cdotprecision::cdotprecision(const l_complex &a)
00043                         : re(Re(_cdotprecision(a))), im(Im(_cdotprecision(a))), k(0){}
00044 
00045 inline cdotprecision::cdotprecision(const real         &r)   
00046                         : re(r), im(0), k(0) {}
00047                         
00048 inline cdotprecision::cdotprecision(const complex      &c)
00049                         : re(Re(c)),im(Im(c)), k(0) {}
00050                         
00051 inline cdotprecision::cdotprecision(const dotprecision &r)
00052                         : re(r), im(0), k(0) { re.set_k(0); im.set_k(0); }
00053                         
00054 inline cdotprecision::cdotprecision(const l_real &r)
00055                         : re(r), im(0), k(0) {}
00056 
00057 
00058 
00059 
00060 inline cdotprecision& cdotprecision::operator= (const real & a)
00061 {
00062    re=a;im=0; return *this;
00063 }
00064 
00065 inline cdotprecision& cdotprecision::operator= (const complex & a) 
00066 {
00067    re=Re(a),im=Im(a); return *this;
00068 }
00069 inline cdotprecision& cdotprecision::operator= (const dotprecision & a)
00070 {
00071    re=a;im=0; return *this;
00072 }
00073 inline cdotprecision& cdotprecision::operator= (const cdotprecision & a)
00074 {
00075    re=a.re,im=a.im; return *this;
00076 }
00077 inline cdotprecision& cdotprecision::operator= (const l_real & a) 
00078 {
00079    re=a;im=0; return *this;
00080 }
00081 
00082 
00083 // ---- Typwandlungen ----
00084 
00090 inline cdotprecision _cdotprecision(const dotprecision& a) 
00091 {
00092   return cdotprecision (a);
00093 }
00099 inline cdotprecision _cdotprecision(const real& a) 
00100 {
00101   return cdotprecision (a);
00102 }
00103 
00109 inline cdotprecision _cdotprecision(const l_real& a) 
00110 { 
00111   return cdotprecision (a);
00112 }
00113 
00119 inline cdotprecision _cdotprecision(const complex& a) 
00120 {
00121   return cdotprecision (a);
00122 }
00123 
00129 inline cdotprecision _cdotprecision(const dotprecision& a, const dotprecision& b) 
00130 {
00131   return cdotprecision (a,b);
00132 }
00138 inline cdotprecision _cdotprecision(const real& a, const real& b) 
00139 {
00140   return cdotprecision (a,b);
00141 }
00142 
00148 inline cdotprecision _cdotprecision(const l_real& a, const l_real& b)
00149 {
00150   return cdotprecision (a,b);
00151 }
00152 
00158 inline cdotprecision _cdotprecision(const l_complex& lc)
00159 {
00160    return cdotprecision(lc);
00161 }
00162 
00163 // ---- Standardfunkt ---- (arithmetische Operatoren)
00164 
00165 inline cdotprecision operator-(const cdotprecision &a) throw() 
00166 { 
00167   return cdotprecision (-a.re, -a.im); 
00168 }
00169 inline cdotprecision operator+(const cdotprecision &a) throw() 
00170 { 
00171   return a; 
00172 }
00173 
00174 inline cdotprecision operator+(const cdotprecision &a,const cdotprecision &b) throw() 
00175 { 
00176   return cdotprecision(a.re+b.re,a.im+b.im); 
00177 }
00178 inline cdotprecision operator-(const cdotprecision &a,const cdotprecision &b) throw() 
00179 { 
00180   return cdotprecision(a.re-b.re,a.im-b.im); 
00181 }
00182 
00183 inline cdotprecision operator +(const cdotprecision &a,const complex &b) throw() { return cdotprecision(a.re+Re(b),a.im+Im(b)); }
00184 inline cdotprecision operator +(const complex &b,const cdotprecision &a) throw() { return cdotprecision(a.re+Re(b),a.im+Im(b)); } 
00185 inline cdotprecision operator -(const cdotprecision &a,const complex &b) throw() { return cdotprecision(a.re-Re(b),a.im-Im(b)); } 
00186 inline cdotprecision operator -(const complex &a,const cdotprecision &b) throw() { return cdotprecision(Re(a)-b.re,Im(a)-b.im); }
00187 
00188 inline cdotprecision operator +(const cdotprecision &a,const dotprecision &b) throw() { return cdotprecision(a.re+b,a.im); }
00189 inline cdotprecision operator +(const dotprecision &b,const cdotprecision &a) throw() { return cdotprecision(a.re+b,a.im); } 
00190 inline cdotprecision operator -(const cdotprecision &a,const dotprecision &b) throw() { return cdotprecision(a.re-b,a.im); } 
00191 inline cdotprecision operator -(const dotprecision &a,const cdotprecision &b) throw() { return cdotprecision(a-b.re,-b.im); }
00192 
00193 inline cdotprecision operator +(const cdotprecision &a,const real &b) throw() { return cdotprecision(a.re+b,a.im); }
00194 inline cdotprecision operator +(const real &b,const cdotprecision &a) throw() { return cdotprecision(a.re+b,a.im); } 
00195 inline cdotprecision operator -(const cdotprecision &a,const real &b) throw() { return cdotprecision(a.re-b,a.im); } 
00196 inline cdotprecision operator -(const real &a,const cdotprecision &b) throw() { return cdotprecision(a-b.re,b.im); }
00197 
00198 inline cdotprecision operator +(const cdotprecision &a, const l_real &b) throw() 
00199 { 
00200   return cdotprecision(a.re+b,a.im);
00201 }
00202 inline cdotprecision operator +(const l_real &b, const cdotprecision &a) throw() 
00203 { 
00204   return cdotprecision(a.re+b,a.im);
00205 }
00206 inline cdotprecision operator -(const cdotprecision &a, const l_real &b) throw() 
00207 { 
00208   return cdotprecision(a.re-b,a.im);
00209 }
00210 inline cdotprecision operator -(const l_real &b, const cdotprecision &a) throw() 
00211 { 
00212   return cdotprecision(b-a.re,-a.im); 
00213 }
00214 
00215 inline cdotprecision & operator +=(cdotprecision &a,const cdotprecision &b) throw() { a.re+=b.re;a.im+=b.im; return a;}
00216 inline cdotprecision & operator +=(cdotprecision &a,const dotprecision &b) throw() { a.re+=b; return a;}
00217 inline cdotprecision & operator -=(cdotprecision &a,const cdotprecision &b) throw() { a.re-=b.re;a.im-=b.im; return a;}
00218 inline cdotprecision & operator -=(cdotprecision &a,const dotprecision &b) throw() { a.re-=b; return a;}
00219 inline cdotprecision & operator +=(cdotprecision &a,const complex &b) throw() 
00220 {
00221    a.re+=Re(b);
00222    a.im+=Im(b);
00223    return a;
00224 }
00225 inline cdotprecision & operator -=(cdotprecision &a,const complex &b) throw()
00226 {
00227    a.re-=Re(b);
00228    a.im-=Im(b);
00229    return a;
00230 }
00231 inline cdotprecision & operator +=(cdotprecision &a,const real &b) throw()
00232 {
00233    a.re+=b;
00234    return a;
00235 }
00236 inline cdotprecision & operator -=(cdotprecision &a,const real &b) throw()
00237 {
00238    a.re-=b;
00239    return a;
00240 }
00241 inline cdotprecision & operator +=(cdotprecision &a,const l_real &b) throw()
00242 { // Blomquist 17.09.02.
00243    a.re+=b;
00244    return a;
00245 }
00246 inline cdotprecision & operator -=(cdotprecision &a,const l_real &b) throw()
00247 { // Blomquist 17.09.02.
00248    a.re-=b;
00249    return a;
00250 }
00251 inline cdotprecision & operator += (cdotprecision &cd, const l_complex &lc) throw() 
00252 {
00253    cd = cd + cdotprecision(lc); return cd;
00254 }
00255 inline cdotprecision & operator -= (cdotprecision &cd, const l_complex &lc) throw() 
00256 {
00257    cd = cd - cdotprecision(lc); return cd;
00258 }
00259       
00260 // --- Vergleichsoperationen ----
00261 inline bool operator ==(const cdotprecision &a,const cdotprecision &b) throw() {   return(a.re==b.re && a.im==b.im); }
00262 inline bool operator !=(const cdotprecision &a,const cdotprecision &b) throw() {   return(a.re!=b.re || a.im!=b.im); }
00263 inline bool operator ==(const dotprecision &r,const cdotprecision &a)     throw() {   return(r==a.re && !a.im); }
00264 inline bool operator !=(const dotprecision &r,const cdotprecision &a)     throw() {   return(r!=a.re || !!a.im); }
00265 inline bool operator ==(const cdotprecision &a,const dotprecision &r)     throw() {   return(r==a.re && !a.im); }
00266 inline bool operator !=(const cdotprecision &a,const dotprecision &r)     throw() {   return(r!=a.re || !!a.im); }
00267 inline bool operator ==(const complex &c,const cdotprecision &a)     throw() {   return(Re(c)==a.re && Im(c)==a.im); }
00268 inline bool operator !=(const complex &c,const cdotprecision &a)     throw() {   return(Re(c)!=a.re || Im(c)!=a.im); }
00269 inline bool operator ==(const cdotprecision &a,const complex &c)     throw() {   return(Re(c)==a.re && Im(c)==a.im); }
00270 inline bool operator !=(const cdotprecision &a,const complex &c)     throw() {   return(Re(c)!=a.re || Im(c)!=a.im); }
00271 inline bool operator ==(const real &c,const cdotprecision &a)     throw() {   return(c==a.re && !a.im); }
00272 inline bool operator !=(const real &c,const cdotprecision &a)     throw() {   return(c!=a.re || !!a.im); }
00273 inline bool operator ==(const cdotprecision &a,const real &c)     throw() {   return(c==a.re && !a.im); }
00274 inline bool operator !=(const cdotprecision &a,const real &c)     throw() {   return(c!=a.re || !!a.im); }
00275 
00276 inline bool operator ==(const l_real &c,const cdotprecision &a) throw() 
00277 { 
00278   return(c==a.re && !a.im);
00279 }
00280 
00281 inline bool operator !=(const l_real &c,const cdotprecision &a) throw()
00282 { 
00283   return(c!=a.re || !!a.im);
00284 }
00285 
00286 inline bool operator ==(const cdotprecision &a,const l_real &c) throw()
00287 { 
00288   return(c==a.re && !a.im);
00289 }
00290 
00291 inline bool operator !=(const cdotprecision &a,const l_real &c) throw()
00292 { 
00293   return(c!=a.re || !!a.im);
00294 }
00295 
00296 // ----- Funktionen -----
00297 inline dotprecision & Re(cdotprecision& a)
00298 { 
00299   return a.re; 
00300 }
00301 
00302 inline dotprecision & Im(cdotprecision& a) throw() 
00303 { 
00304   return a.im;
00305 }
00306 
00307 inline const dotprecision & Re(const cdotprecision& a)
00308 { 
00309   return a.re; 
00310 }
00311 
00312 inline const dotprecision & Im(const cdotprecision& a) throw()
00313 { 
00314   return a.im; 
00315 }
00316 
00317 inline cdotprecision& SetRe (cdotprecision& a, const dotprecision& b)  throw()
00318 {                         // ggf. exception
00319    a.re=b; 
00320    return a;
00321 }
00322 
00323 inline cdotprecision& SetIm (cdotprecision& a, const dotprecision& b) throw()
00324 {
00325    a.im=b;
00326    return a;
00327 }
00328 
00329 inline cdotprecision conj(const cdotprecision& a) throw()
00330 {
00331    return cdotprecision(a.re,-a.im);
00332 }
00333 
00334 inline bool operator !(const cdotprecision &a) throw() 
00335 { 
00336    return !a.re && !a.im;
00337 }  
00338 
00339 inline void accumulate  (cdotprecision & a, const complex & b, const real & c) throw()
00340 { 
00341   accumulate(a,b,complex(c));
00342 }
00343 
00344 inline void accumulate  (cdotprecision & a, const real & b, const complex & c) throw()
00345 { 
00346   accumulate(a,complex(b),c);
00347 }
00348 
00349 inline void accumulate  (cdotprecision & a, const real & b, const real & c) throw()
00350 { 
00351   accumulate(a,complex(b),complex(c)); 
00352 }
00353 
00354 } // namespace cxsc
00355