Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/math/complex.h

Go to the documentation of this file.
00001 //  more/complex.h -- extensions to comlex
00002 //  Copyright (C) 1998--2001  Petter Urkedal (petter.urkedal@matfys.lth.se)
00003 
00004 //  This file is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 
00009 //  This file is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 //  As a special exception, you may use this file as part of a free
00019 //  software library without restriction.  Specifically, if other files
00020 //  instantiate templates or use macros or inline functions from this
00021 //  file, or you compile this file and link it with other files to
00022 //  produce an executable, this file does not by itself cause the
00023 //  resulting executable to be covered by the GNU General Public
00024 //  License.  This exception does not however invalidate any other
00025 //  reasons why the executable file might be covered by the GNU General
00026 //  Public License.
00027 
00028 //  $Id: complex.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00029 
00030 
00031 
00032 #ifndef MORE_MATH_COMPLEX_H
00033 #define MORE_MATH_COMPLEX_H
00034 
00035 #include <complex>
00036 #include <more/bits/mathbits.h>
00037 #include <more/io/fwd.h>
00038 
00039 namespace more {
00040 namespace math {
00041 
00042     using std::complex;
00043     using std::real;
00044     using std::imag;
00045     using std::norm;
00046     using std::conj;
00047     using std::operator+;
00048     using std::operator-;
00049     using std::operator*;
00050     using std::operator/;
00051 
00052 //      template<typename T>
00053 //        struct category_< std::complex<T> > { typedef complex_tag eval; };
00054 
00055 
00056     //  ---   s p e c i a l   n u m b e r s   ---
00057 
00058     //  --- imaginary unit ---
00059 
00060     struct onei_tag {
00061         operator complex<char>() const { return complex<char>(0, 1); }
00062         operator complex<short>() const { return complex<short>(0, 1); }
00063         operator complex<int>() const { return complex<int>(0, 1); }
00064         operator complex<long>() const { return complex<long>(0, 1l); }
00065         operator complex<float>() const
00066             { return complex<float>(0.0f, 1.0f); }
00067         operator complex<double>() const
00068             { return complex<double>(0.0, 1.0); }
00069         operator complex<long double>() const
00070             { return complex<long double>(0.0l, 1.0l); }
00071     };
00072     extern onei_tag onei;
00073     struct minus_onei_tag {
00074         operator complex<char>() const { return complex<char>(0, -1); }
00075         operator complex<short>() const { return complex<short>(0, -1); }
00076         operator complex<int>() const { return complex<int>(0, -1); }
00077         operator complex<long>() const { return complex<long>(0, -1l); }
00078         operator complex<float>() const
00079             { return complex<float>(0.0f, -1.0f); }
00080         operator complex<double>() const
00081             { return complex<double>(0.0, -1.0); }
00082         operator complex<long double>() const
00083             { return complex<long double>(0.0l, -1.0l); }
00084     };
00085     inline minus_onei_tag operator-(onei_tag)
00086         { return minus_onei_tag(); }
00087     inline onei_tag operator-(minus_onei_tag) { return onei; }
00088 
00089     template<typename T>
00090       inline complex<T> operator*(const complex<T>& x, onei_tag)
00091         { return complex<T>(-imag(x), real(x)); }
00092     template<typename T>
00093       inline complex<T> operator*(onei_tag, const complex<T>& y)
00094         { return complex<T>(-imag(y), real(y)); }
00095     template<typename T>
00096       inline complex<T> operator*(const complex<T>& x, minus_onei_tag)
00097         { return complex<T>(imag(x), -real(x)); }
00098     template<typename T>
00099       inline complex<T> operator*(minus_onei_tag, const complex<T>& y)
00100         { return complex<T>(imag(y), -real(y)); }
00101 
00102     inline complex<float>
00103       operator*(float x, onei_tag) { return complex<float>(0.0f, x); }
00104     inline complex<double>
00105       operator*(double x, onei_tag) { return complex<double>(0.0, x); }
00106     inline complex<long double>
00107       operator*(long double x, onei_tag)
00108         { return complex<long double>(0.0l, x); }
00109     inline complex<float>
00110       operator*(float x, minus_onei_tag) { return complex<float>(0.0f, -x); }
00111     inline complex<double>
00112       operator*(double x, minus_onei_tag) { return complex<double>(0.0, -x); }
00113     inline complex<long double>
00114       operator*(long double x, minus_onei_tag)
00115         { return complex<long double>(0.0l, -x); }
00116     inline complex<float>
00117       operator*(onei_tag, float x) { return complex<float>(0.0f, x); }
00118     inline complex<double>
00119       operator*(onei_tag, double x) { return complex<double>(0.0, x); }
00120     inline complex<long double>
00121       operator*(onei_tag, long double x)
00122         { return complex<long double>(0.0l, x); }
00123     inline complex<float>
00124       operator*(minus_onei_tag, float x) { return complex<float>(0.0f, -x); }
00125     inline complex<double>
00126       operator*(minus_onei_tag, double x) { return complex<double>(0.0, -x); }
00127     inline complex<long double>
00128       operator*(minus_onei_tag, long double x)
00129         { return complex<long double>(0.0l, -x); }
00130 
00131 
00132     template<typename T>
00133       struct norm_type_< complex<T> > { typedef T eval; };
00134     template<typename T>
00135       struct scalar_type_< complex<T> > { typedef complex<T> eval; };
00136     template<typename T>
00137       struct outer_product_type_< complex<T> > { typedef complex<T> eval; };
00138 
00139 
00140     // --- some scalar extensions of tensor operations ---
00141 
00142     template<typename T> inline int rank(complex<T> const&) { return 0; }
00143     template<typename T> inline int size0(complex<T> const&) { return 1; }
00144     template<typename T> inline int size1(complex<T> const&) { return 1; }
00145     template<typename T> inline int size2(complex<T> const&) { return 1; }
00146 
00147     template<typename T> inline complex<T> trace(complex<T> const& x)
00148         { return x; }
00149     template<typename T> inline complex<T> adj(complex<T> const& x)
00150         { return conj(x); }
00151 
00152     inline float adj(float x) { return x; }
00153     inline double adj(double x) { return x; }
00154     inline long double adj(long double x) { return x; }
00155 #if 0 // fixme: compiler bug
00156     inline complex<float>
00157       dot(complex<float> const& x, complex<float> const& y)
00158         { return conj(x)*y; }
00159     inline complex<double>
00160       dot(complex<double> const& x, complex<double> const& y)
00161         { return conj(x)*y; }
00162     inline complex<long double>
00163       dot(complex<long double> const& x, complex<long double> const& y)
00164         { return conj(x)*y; }
00165 #else
00166     inline complex<float>
00167       dot(complex<float> const& x, complex<float> const& y)
00168         { complex<float> tmp = conj(x); tmp *= y; return tmp; }
00169     inline complex<double>
00170       dot(complex<double> const& x, complex<double> const& y)
00171         { complex<double> tmp = conj(x); tmp *= y; return tmp; }
00172     inline complex<long double>
00173       dot(complex<long double> const& x, complex<long double> const& y)
00174         { complex<long double> tmp = conj(x); tmp *= y; return tmp; }
00175 #endif
00176 
00177     template<typename T> inline int finite(complex<T> const& x) {
00178         return more::finite(real(x)) && more::finite(imag(x));
00179     }
00180 
00181 } // namespace more
00182   using namespace math;
00183 }
00184 
00185 #endif

Generated on Sat Sep 7 19:11:17 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.