CppAD: A C++ Algorithmic Differentiation Package
20130918
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_BASE_FLOAT_INCLUDED 00003 # define CPPAD_BASE_FLOAT_INCLUDED 00004 /* -------------------------------------------------------------------------- 00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell 00006 00007 CppAD is distributed under multiple licenses. This distribution is under 00008 the terms of the 00009 Eclipse Public License Version 1.0. 00010 00011 A copy of this license is included in the COPYING file of this distribution. 00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00013 -------------------------------------------------------------------------- */ 00014 # include <limits> 00015 00016 /* 00017 $begin base_float.hpp$$ 00018 $spell 00019 abs_geq 00020 acos 00021 asin 00022 atan 00023 cos 00024 sqrt 00025 tanh 00026 std 00027 fabs 00028 bool 00029 Lt Le Eq Ge Gt 00030 Rel 00031 CppAD 00032 CondExpOp 00033 namespace 00034 inline 00035 enum 00036 const 00037 exp 00038 const 00039 $$ 00040 00041 $index float, Base$$ 00042 $index Base, float$$ 00043 $index float, Base$$ 00044 00045 $section Enable use of AD<Base> where Base is float$$ 00046 00047 $head CondExpOp$$ 00048 The type $code float$$ is a relatively simple type that supports 00049 $code <$$, $code <=$$, $code ==$$, $code >=$$, and $code >$$ operators; see 00050 $cref/ordered type/base_cond_exp/CondExpTemplate/Ordered Type/$$. 00051 Hence its $code CondExpOp$$ function is defined by 00052 $codep */ 00053 namespace CppAD { 00054 inline float CondExpOp( 00055 enum CompareOp cop , 00056 const float& left , 00057 const float& right , 00058 const float& exp_if_true , 00059 const float& exp_if_false ) 00060 { return CondExpTemplate(cop, left, right, exp_if_true, exp_if_false); 00061 } 00062 } 00063 /* $$ 00064 00065 $head CondExpRel$$ 00066 The $cref/CPPAD_COND_EXP_REL/base_cond_exp/CondExpRel/$$ macro invocation 00067 $codep */ 00068 namespace CppAD { 00069 CPPAD_COND_EXP_REL(float) 00070 } 00071 /* $$ 00072 uses $code CondExpOp$$ above to 00073 define $codei%CondExp%Rel%$$ for $code float$$ arguments 00074 and $icode%Rel%$$ equal to 00075 $code Lt$$, $code Le$$, $code Eq$$, $code Ge$$, and $code Gt$$. 00076 00077 $head EqualOpSeq$$ 00078 The type $code float$$ is simple (in this respect) and so we define 00079 $codep */ 00080 namespace CppAD { 00081 inline bool EqualOpSeq(const float& x, const float& y) 00082 { return x == y; } 00083 } 00084 /* $$ 00085 00086 $head Identical$$ 00087 The type $code float$$ is simple (in this respect) and so we define 00088 $codep */ 00089 namespace CppAD { 00090 inline bool IdenticalPar(const float& x) 00091 { return true; } 00092 inline bool IdenticalZero(const float& x) 00093 { return (x == 0.f); } 00094 inline bool IdenticalOne(const float& x) 00095 { return (x == 1.f); } 00096 inline bool IdenticalEqualPar(const float& x, const float& y) 00097 { return (x == y); } 00098 } 00099 /* $$ 00100 00101 $head Integer$$ 00102 $codep */ 00103 namespace CppAD { 00104 inline int Integer(const float& x) 00105 { return static_cast<int>(x); } 00106 } 00107 /* $$ 00108 00109 $head Ordered$$ 00110 The $code float$$ type supports ordered comparisons 00111 $codep */ 00112 namespace CppAD { 00113 inline bool GreaterThanZero(const float& x) 00114 { return x > 0.f; } 00115 inline bool GreaterThanOrZero(const float& x) 00116 { return x >= 0.f; } 00117 inline bool LessThanZero(const float& x) 00118 { return x < 0.f; } 00119 inline bool LessThanOrZero(const float& x) 00120 { return x <= 0.f; } 00121 inline bool abs_geq(const float& x, const float& y) 00122 { return std::fabs(x) >= std::fabs(y); } 00123 } 00124 /* $$ 00125 00126 $head Unary Standard Math$$ 00127 The following macro invocations define the unary standard math functions 00128 required to use $code AD<float>$$: 00129 (in the CppAD namespace) 00130 $codep */ 00131 namespace CppAD { 00132 CPPAD_STANDARD_MATH_UNARY(float, acos) 00133 CPPAD_STANDARD_MATH_UNARY(float, asin) 00134 CPPAD_STANDARD_MATH_UNARY(float, atan) 00135 CPPAD_STANDARD_MATH_UNARY(float, cos) 00136 CPPAD_STANDARD_MATH_UNARY(float, cosh) 00137 CPPAD_STANDARD_MATH_UNARY(float, exp) 00138 CPPAD_STANDARD_MATH_UNARY(float, fabs) 00139 CPPAD_STANDARD_MATH_UNARY(float, log) 00140 CPPAD_STANDARD_MATH_UNARY(float, log10) 00141 CPPAD_STANDARD_MATH_UNARY(float, sin) 00142 CPPAD_STANDARD_MATH_UNARY(float, sinh) 00143 CPPAD_STANDARD_MATH_UNARY(float, sqrt) 00144 CPPAD_STANDARD_MATH_UNARY(float, tan) 00145 CPPAD_STANDARD_MATH_UNARY(float, tanh) 00146 } 00147 /* $$ 00148 The absolute value function is special because its $code std$$ name is 00149 $code fabs$$ 00150 $codep */ 00151 namespace CppAD { 00152 inline float abs(const float& x) 00153 { return std::fabs(x); } 00154 } 00155 /* $$ 00156 00157 $head sign$$ 00158 The following defines the $code CppAD::sign$$ function that 00159 is required to use $code AD<float>$$: 00160 $codep */ 00161 namespace CppAD { 00162 inline float sign(const float& x) 00163 { if( x > 0.f ) 00164 return 1.f; 00165 if( x == 0.f ) 00166 return 0.f; 00167 return -1.f; 00168 } 00169 } 00170 /* $$ 00171 00172 $head pow $$ 00173 The following defines a $code CppAD::pow$$ function that 00174 is required to use $code AD<float>$$: 00175 $codep */ 00176 namespace CppAD { 00177 inline float pow(const float& x, const float& y) 00178 { return std::pow(x, y); } 00179 } 00180 /*$$ 00181 00182 $head limits$$ 00183 The following defines the numeric limits functions 00184 $code epsilon$$, $code min$$, and $code max$$ for the type 00185 $code float$$: 00186 $codep */ 00187 namespace CppAD { 00188 template <> 00189 class numeric_limits<float> { 00190 public: 00191 // machine epsilon 00192 static float epsilon(void) 00193 { return std::numeric_limits<float>::epsilon(); } 00194 // minimum positive normalized value 00195 static float min(void) 00196 { return std::numeric_limits<float>::min(); } 00197 // maximum finite value 00198 static float max(void) 00199 { return std::numeric_limits<float>::max(); } 00200 }; 00201 // deprecated machine epsilon 00202 template <> 00203 inline float epsilon<float>(void) 00204 { return numeric_limits<float>::epsilon(); } 00205 } 00206 /* $$ 00207 $end 00208 */ 00209 00210 00211 # endif