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

more/math/mathbits.h

Go to the documentation of this file.
00001 //  more/bits/mathbits.h -- used by math.h and complex.h
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: mathbits.h,v 1.1 2002/05/30 18:01:38 petter_urkedal Exp $
00029 
00030 
00031 
00032 #ifndef MORE_MATHBITS_H
00033 #define MORE_MATHBITS_H
00034 
00035 #include <more/meta.h>
00036 
00037 namespace more {
00038 namespace math {
00039 
00040   // --- traits ---
00041 
00042   template<typename T>
00043     struct undefined_type {};
00044 
00045   template<typename T> struct scalar_type_
00046     { typedef typename T::scalar_type eval; };
00047   template<typename T> struct scalar_type_<const T>
00048     { typedef const typename scalar_type_<T>::eval eval; };
00049   template<> struct scalar_type_<float> { typedef float eval; };
00050   template<> struct scalar_type_<double> { typedef double eval; };
00051   template<> struct scalar_type_<long double> { typedef long double eval; };
00052   template<> struct scalar_type_<int> { typedef int eval; };
00053 
00054   template<typename T> struct norm_type_
00055     { typedef typename scalar_type_<T>::eval eval; };
00056   template<typename T> struct norm_type_<const T>
00057     { typedef const typename norm_type_<T>::eval eval; };
00058 
00059   template<typename T>
00060     struct element_type_ { typedef typename T::element_type eval; };
00061 
00062   template<typename T>
00063     struct position_type_ { typedef typename T::position_type eval; };
00064 
00065   template<typename T>
00066     struct outer_product_type_ {
00067         typedef typename T::outer_product_type eval;
00068     };
00069   template<typename T> struct outer_product_type_<const T>
00070       { typedef const typename outer_product_type_<T>::eval eval; };
00071   template<> struct outer_product_type_<float> { typedef float eval; };
00072   template<> struct outer_product_type_<double> { typedef double eval; };
00073   template<> struct outer_product_type_<long double>
00074     { typedef long double eval; };
00075   template<> struct outer_product_type_<int> { typedef int eval; };
00076 
00077   template<typename T, typename U> struct balanced_type_
00078       { typedef typename bigger_type_<T, U>::eval eval; };
00079 
00080   template<typename T, typename U> struct times_type_
00081       { typedef typename balanced_type_<T, U>::eval eval; };
00082 
00083   template<typename T, typename U> struct divides_type_
00084       { typedef typename balanced_type_<T, U>::eval eval; };
00085 
00086   template<typename T, typename U> struct plus_type_
00087       { typedef typename balanced_type_<T, U>::eval eval; };
00088 
00089   template<typename T, typename U> struct minus_type_
00090       { typedef typename balanced_type_<T, U>::eval eval; };
00091 
00092 
00093   template<typename T> struct size_
00094       { static int const eval = T::CTC_size; };
00095 
00096 
00097     // --- zero and one ---
00098 
00099     struct zero_tag {
00100         operator char() const { return 0; }
00101         operator short() const { return 0; }
00102         operator int() const { return 0; }
00103         operator long() const { return 0L; }
00104         operator unsigned long() const { return 0L; }
00105         operator float() const { return 0.0F; }
00106         operator double() const { return 0.0; }
00107         operator long double() const { return 0.0L; }
00108         // Complex is taken care of by zero_tag --> T --> complex<T>.
00109 //      operator std::complex<float>() const
00110 //          { return std::complex<float>(zero_tag(), zero_tag()); }
00111 //      operator std::complex<double>() const
00112 //          { return std::complex<double>(zero_tag(), zero_tag()); }
00113 //      operator std::complex<long double>() const
00114 //          { return std::complex<long double>(zero_tag(), zero_tag()); }
00115     };
00116     extern zero_tag zero;
00117 
00118     struct one_tag {
00119         operator char() const { return 1; }
00120         operator short() const { return 1; }
00121         operator int() const { return 1; }
00122         operator long() const { return 1L; }
00123         operator unsigned long() const { return 1L; }
00124         operator float() const { return 1.0F; }
00125         operator double() const { return 1.0; }
00126         operator long double() const { return 1.0L; }
00127         // Complex is taken care of by zero_tag --> T --> complex<T>.
00128 //      operator std::complex<float>() const
00129 //          { return std::complex<float>(one_tag(), zero_tag()); }
00130 //      operator std::complex<double>() const
00131 //          { return std::complex<double>(one_tag(), zero_tag()); }
00132 //      operator std::complex<long double>() const
00133 //          { return std::complex<long double>(one_tag(), zero_tag()); }
00134     };
00135     extern one_tag one;
00136 
00137     struct minus_one_tag {
00138         operator char() const { return 1; }
00139         operator short() const { return 1; }
00140         operator int() const { return 1; }
00141         operator long() const { return 1L; }
00142         operator unsigned long() const { return 1L; }
00143         operator float() const { return 1.0F; }
00144         operator double() const { return 1.0; }
00145         operator long double() const { return 1.0L; }
00146 //      operator std::complex<float>() const
00147 //          { return std::complex<float>(minus_one_tag(), zero_tag()); }
00148 //      operator std::complex<double>() const
00149 //          { return std::complex<double>(minus_one_tag(), zero_tag()); }
00150 //      operator std::complex<long double>() const
00151 //          { return std::complex<long double>(minus_one_tag(), zero_tag()); }
00152     };
00153 
00154     inline one_tag operator+(one_tag) { return one_tag(); }
00155     inline minus_one_tag operator+(minus_one_tag) { return minus_one_tag(); }
00156     inline minus_one_tag operator-(one_tag) { return minus_one_tag(); }
00157     inline one_tag operator-(minus_one_tag) { return one_tag(); }
00158 
00159     template<typename T>
00160       inline zero_tag operator*(zero_tag, T) { return zero; }
00161     template<typename T>
00162       inline zero_tag operator*(T, zero_tag) { return zero; }
00163     template<typename T>
00164       inline zero_tag operator/(zero_tag, T) { return zero; }
00165     template<typename T>
00166       inline T operator+(zero_tag, const T& x) { return x; }
00167     template<typename T>
00168       inline T operator+(const T& x, zero_tag) { return x; }
00169     template<typename T>
00170       inline T operator-(zero_tag, const T& x) { return -x; }
00171     template<typename T>
00172       inline T operator-(const T& x, zero_tag) { return x; }
00173     template<typename T>
00174       inline T operator*(one_tag, const T& x) { return x; }
00175     template<typename T>
00176       inline T operator*(const T& x, one_tag) { return x; }
00177     template<typename T>
00178       inline T operator/(const T&x, one_tag) { return x; }
00179     template<typename T>
00180       inline T operator*(minus_one_tag, const T& x) { return -x; }
00181     template<typename T>
00182       inline T operator*(const T& x, minus_one_tag) { return -x; }
00183     template<typename T>
00184       inline T operator/(const T&x, minus_one_tag) { return -x; }
00185 
00186 }
00187   using namespace math;
00188 }
00189 #endif

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