complex.inl

00001 /*
00002 **  CXSC is a C++ library for eXtended Scientific Computing (V 2.5.1)
00003 **
00004 **  Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
00005 **                          Universitaet Karlsruhe, Germany
00006 **            (C) 2000-2011 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.inl,v 1.20 2011/06/07 15:17:38 cxsc Exp $ */
00025 
00026 
00027 namespace cxsc {
00028 // ---- Constructors ----------------------------------------------
00029 
00030 inline complex & complex::operator= (const real & r) throw()
00031 {
00032    re=r;im=0;
00033    return *this;
00034 }
00035 
00036       // ---- Std.Operators ---------------------------------------
00037 inline complex operator -(const complex &a) throw () 
00038 {
00039    return complex(-a.re,-a.im);
00040 }
00041 
00042 inline complex operator +(const complex &a) throw ()
00043 {
00044    return a;
00045 }
00046 
00047 inline complex operator +(const complex &a,const complex &b) throw()
00048 {
00049    return complex(a.re+b.re,a.im+b.im);
00050 }
00051 
00052 inline complex operator -(const complex &a,const complex &b) throw()
00053 {
00054    return complex(a.re-b.re,a.im-b.im);
00055 }
00056 
00057 inline complex & operator +=(complex &a, const complex &b) throw() { return a=a+b; }
00058 inline complex & operator -=(complex &a, const complex &b) throw() { return a=a-b; }
00059 inline complex & operator *=(complex &a, const complex &b) throw() { return a=a*b; }
00060 inline complex & operator /=(complex &a, const complex &b) throw() { return a=a/b; }
00061 
00062 inline complex operator +(const complex & a,const real & b) throw() 
00063 { 
00064    return complex(a.re+b,a.im);
00065 }
00066 
00067 inline complex operator +(const real & a,const complex & b) throw()
00068 {
00069    return complex(a+b.re,b.im);
00070 }
00071 
00072 inline complex operator -(const complex & a,const real & b) throw()
00073 {
00074    return complex(a.re-b,a.im);
00075 }
00076 
00077 inline complex operator -(const real & a,const complex & b) throw()
00078 {
00079    return complex(a-b.re,-b.im);
00080 }
00081 
00082 inline complex operator *(const complex & a,const real & b) throw()
00083 {
00084 //   return a*_complex(b);
00085      return complex(a.re*b,a.im*b);  // Blomquist, 07.11.02;
00086 }
00087 
00088 inline complex operator *(const real & a,const complex & b) throw()
00089 {
00090 //   return _complex(a)*b;
00091      return complex(a*b.re, a*b.im);  // Blomquist, 07.11.02;
00092 }
00093 
00094 inline complex operator /(const complex & a,const real & b) throw()
00095 {
00096 //   return a/_complex(b);
00097      return complex(a.re/b, a.im/b);  // Blomquist, 07.11.02;
00098 }
00099 
00100 inline complex operator /(const real & a,const complex & b) throw()
00101 {
00102    return _complex(a)/b;
00103 }
00104 
00105 inline complex & operator +=(complex & a, const real & b) throw() { return a=a+b; }
00106 inline complex & operator -=(complex & a, const real & b) throw() { return a=a-b; }
00107 inline complex & operator *=(complex & a, const real & b) throw() { return a=a*b; }
00108 inline complex & operator /=(complex & a, const real & b) throw() { return a=a/b; }
00109 
00110       // ---- Comp.Operat.  ---------------------------------------
00111 inline bool operator!  (const complex & a)                    throw() { return !a.re && !a.im; }
00112 inline bool operator== (const complex & a, const complex & b) throw() { return a.re==b.re && a.im==b.im; }
00113 inline bool operator!= (const complex & a, const complex & b) throw() { return a.re!=b.re || a.im!=b.im; }
00114 inline bool operator== (const complex & a, const real & b)    throw() { return !a.im && a.re==b; }
00115 inline bool operator== (const real & a, const complex & b)    throw() { return !b.im && a==b.re; }
00116 inline bool operator!= (const complex & a, const real & b)    throw() { return !!a.im || a.re!=b; }
00117 inline bool operator!= (const real & a, const complex & b)    throw() { return !!b.im || a!=b.re; }
00118 
00119       // ---- Others   -------------------------------------------
00120 
00121 inline complex conj(const complex & a) throw() { return complex(a.re,-a.im); }
00122 
00123 
00124 // ----------- Directed Rounding, Blomquist -------------------------------
00125 // ------------------------------------------------------------------------
00126 
00127    // -------------------- addition --------------------------------
00128 
00129 inline complex addd(const complex& a, const complex& b) throw()
00130 { return complex(addd(a.re,b.re), addd(a.im,b.im)); }
00131 
00132 inline complex addu(const complex& a, const complex& b) throw()
00133 { return complex(addu(a.re,b.re), addu(a.im,b.im)); }
00134 
00135 inline complex addd(const complex& a, const real& b) throw()
00136 { return complex(addd(a.re,b), a.im); }
00137 
00138 inline complex addu(const complex& a, const real& b) throw()
00139 { return complex(addu(a.re,b), a.im); }
00140 
00141 inline complex addd(const real& a, const complex& b) throw()
00142 { return complex(addd(a,b.re), b.im); }
00143 
00144 inline complex addu(const real& a, const complex& b) throw()
00145 { return complex(addu(a,b.re), b.im); }
00146    // ----------------- subtraction: ----------------------------
00147 
00148 inline complex subd(const complex& a, const complex& b) throw()
00149 { return complex(subd(a.re,b.re), subd(a.im,b.im)); }
00150 
00151 inline complex subu(const complex& a, const complex& b) throw()
00152 { return complex(subu(a.re,b.re), subu(a.im,b.im)); }
00153 
00154 inline complex subd(const complex& a, const real& b) throw()
00155 { return complex(subd(a.re,b), a.im); }
00156 
00157 inline complex subu(const complex& a, const real& b) throw()
00158 { return complex(subu(a.re,b), a.im); }
00159 
00160 inline complex subd(const real& a, const complex& b) throw()
00161 { return complex(subd(a,b.re), -b.im); }
00162 
00163 inline complex subu(const real& a, const complex& b) throw()
00164 { return complex(subu(a,b.re), -b.im); }
00165 
00166    // --------------- multiplikation ------------------------
00167 
00168 inline complex muld(const complex &a, const real &b) throw()
00169 { return complex( muld(a.re,b), muld(a.im,b) ); }
00170 
00171 inline complex mulu(const complex &a, const real &b) throw()
00172 { return complex( mulu(a.re,b), mulu(a.im,b) ); }
00173 
00174 inline complex muld(const real &a, const complex &b) throw()
00175 { return complex( muld(a,b.re), muld(a,b.im) ); }
00176 
00177 inline complex mulu(const real &a, const complex &b) throw()
00178 { return complex( mulu(a,b.re), mulu(a,b.im) ); }
00179 
00180    // -------------- division ---------------------------------
00181 
00182 inline complex divd(const complex &a, const real &b) throw()
00183 { return complex( divd(a.re,b), divd(a.im,b) ); }
00184 
00185 inline complex divu(const complex &a, const real &b) throw()
00186 { return complex( divu(a.re,b), divu(a.im,b) ); }
00187 
00188 inline complex divd(const real &a, const complex &b) throw()
00189 { return divd(_complex(a),b); }
00190 
00191 inline complex divu(const real &a, const complex &b) throw()
00192 { return divu(_complex(a),b); }
00193 } // namespace cxsc
00194 

Generated on Thu Jun 9 11:20:44 2011 for C-XSC - A C++ Class Library for Extended Scientific Computing by  doxygen 1.4.6