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

more/gen/lambda_math.h

Go to the documentation of this file.
00001 //  more/lambda_math.h -- lambda-overloads for basic math functions
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: lambda_math.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00029 
00030 
00031 #ifndef MORE_GEN_LAMBDA_MATH_H
00032 #define MORE_GEN_LAMBDA_MATH_H
00033 
00034 #include <cmath>
00035 #include <cstdlib>
00036 #include <more/math/math.h>
00037 
00038 namespace more {
00039 namespace gen {
00040 
00041   ///\if bits
00042   namespace lambda_kns {
00043 #define MORE_DEF(Name, Result)\
00044     using more::Name;\
00045     template<typename Expr> struct Name##_expr {};\
00046     template<typename Expr>\
00047     struct expr< Name##_expr<Expr> > {\
00048         typedef typename Expr::result_type argument_type;\
00049         typedef Result result_type;\
00050         template<typename Assign>\
00051         result_type operator()(const Assign& a) {\
00052             return Name(x(a));\
00053         }\
00054         template<typename Assign>\
00055         result_type operator()(const Assign& a) const {\
00056             return Name(x(a));\
00057         }\
00058         explicit expr(const Expr& x_) : x(x_) {}\
00059     private:\
00060         Expr x;\
00061     };\
00062     template<typename Expr>\
00063     expr< Name##_expr< expr<Expr> > >\
00064     Name(const expr<Expr>& x) {\
00065         return expr< Name##_expr< expr<Expr> > >(x);\
00066     }
00067 //#enddef
00068 
00069     MORE_DEF(ceil, argument_type)  MORE_DEF(floor, argument_type)
00070     MORE_DEF(sin, argument_type)   MORE_DEF(cos, argument_type)
00071     MORE_DEF(tan, argument_type)
00072     MORE_DEF(asin, argument_type)  MORE_DEF(acos, argument_type)
00073     MORE_DEF(atan, argument_type)
00074     MORE_DEF(sinh, argument_type)  MORE_DEF(cosh, argument_type)
00075     MORE_DEF(tanh, argument_type)  MORE_DEF(exp, argument_type)
00076     MORE_DEF(log, argument_type)   MORE_DEF(log10, argument_type)
00077     MORE_DEF(sqrt, argument_type)
00078     MORE_DEF(pow2, argument_type)  MORE_DEF(pow3, argument_type)
00079     MORE_DEF(fabs, typename norm_type_<argument_type>::eval)
00080     MORE_DEF(abs,  typename norm_type_<argument_type>::eval)
00081 //    MORE_DEF(norm, norm_type_<argument_type>::eval)
00082     MORE_DEF(norm, double)
00083 #undef MORE_DEF
00084 
00085 #define MORE_DEF(Name)\
00086     using more::Name;\
00087     template<typename Expr1, typename Expr2> struct Name##_expr {};\
00088     template<typename Expr1, typename Expr2>\
00089       struct expr< Name##_expr<Expr1, Expr2> > {\
00090           typedef typename Expr1::result_type result_type;\
00091           template<typename Assign>\
00092             result_type operator()(const Assign& a) {\
00093                 return Name(x(a), y(a));\
00094           }\
00095           template<typename Assign>\
00096             result_type operator()(const Assign& a) const {\
00097                 return Name(x(a), y(a));\
00098             }\
00099           expr(const Expr1& x_, const Expr2& y_) : x(x_), y(y_) {}\
00100         private:\
00101           Expr1 x;\
00102           Expr2 y;\
00103       };\
00104     template<typename T1, typename T2>\
00105       expr<Name##_expr< typename which_expr<T1>::eval,\
00106                         typename which_expr<T2>::eval > >\
00107       Name(const T1& x, const T2& y) {\
00108           return expr< Name##_expr< typename which_expr<T1>::eval,\
00109                                     typename which_expr<T2>::eval > >(x, y);\
00110       }
00111 //#enddef
00112 
00113     MORE_DEF(atan2) MORE_DEF(fmod)
00114     MORE_DEF(ldexp) // obs: different type args
00115     MORE_DEF(pow) // obs: different or equal args
00116 #undef MORE_DEF
00117   }
00118   ///\endif
00119 
00120 }} // more::gen
00121 
00122 #endif

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