CppAD: A C++ Algorithmic Differentiation Package
20130102
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_BASE_DOUBLE_INCLUDED 00003 # define CPPAD_BASE_DOUBLE_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_double.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 double, Base$$ 00042 $index Base, double$$ 00043 $index double, Base$$ 00044 00045 $section Enable use of AD<Base> where Base is double$$ 00046 00047 $head CondExpOp$$ 00048 The type $code double$$ 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 double CondExpOp( 00055 enum CompareOp cop , 00056 const double& left , 00057 const double& right , 00058 const double& exp_if_true , 00059 const double& 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(double) 00070 } 00071 /* $$ 00072 uses $code CondExpOp$$ above to 00073 define $codei%CondExp%Rel%$$ for $code double$$ 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 double$$ is simple (in this respect) and so we define 00079 $codep */ 00080 namespace CppAD { 00081 inline bool EqualOpSeq(const double& x, const double& y) 00082 { return x == y; } 00083 } 00084 /* $$ 00085 00086 $head Identical$$ 00087 The type $code double$$ is simple (in this respect) and so we define 00088 $codep */ 00089 namespace CppAD { 00090 inline bool IdenticalPar(const double& x) 00091 { return true; } 00092 inline bool IdenticalZero(const double& x) 00093 { return (x == 0.); } 00094 inline bool IdenticalOne(const double& x) 00095 { return (x == 1.); } 00096 inline bool IdenticalEqualPar(const double& x, const double& y) 00097 { return (x == y); } 00098 } 00099 /* $$ 00100 00101 $head Integer$$ 00102 $codep */ 00103 namespace CppAD { 00104 inline int Integer(const double& x) 00105 { return static_cast<int>(x); } 00106 } 00107 /* $$ 00108 00109 $head Ordered$$ 00110 The $code double$$ type supports ordered comparisons 00111 $codep */ 00112 namespace CppAD { 00113 inline bool GreaterThanZero(const double& x) 00114 { return x > 0.; } 00115 inline bool GreaterThanOrZero(const double& x) 00116 { return x >= 0.; } 00117 inline bool LessThanZero(const double& x) 00118 { return x < 0.; } 00119 inline bool LessThanOrZero(const double& x) 00120 { return x <= 0.; } 00121 inline bool abs_geq(const double& x, const double& 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<double>$$: 00129 $codep */ 00130 namespace CppAD { 00131 CPPAD_STANDARD_MATH_UNARY(double, acos) 00132 CPPAD_STANDARD_MATH_UNARY(double, asin) 00133 CPPAD_STANDARD_MATH_UNARY(double, atan) 00134 CPPAD_STANDARD_MATH_UNARY(double, cos) 00135 CPPAD_STANDARD_MATH_UNARY(double, cosh) 00136 CPPAD_STANDARD_MATH_UNARY(double, exp) 00137 CPPAD_STANDARD_MATH_UNARY(double, fabs) 00138 CPPAD_STANDARD_MATH_UNARY(double, log) 00139 CPPAD_STANDARD_MATH_UNARY(double, log10) 00140 CPPAD_STANDARD_MATH_UNARY(double, sin) 00141 CPPAD_STANDARD_MATH_UNARY(double, sinh) 00142 CPPAD_STANDARD_MATH_UNARY(double, sqrt) 00143 CPPAD_STANDARD_MATH_UNARY(double, tan) 00144 CPPAD_STANDARD_MATH_UNARY(double, tanh) 00145 } 00146 /* $$ 00147 The absolute value function is special because its $code std$$ name is 00148 $code fabs$$ 00149 $codep */ 00150 namespace CppAD { 00151 inline double abs(const double& x) 00152 { return std::fabs(x); } 00153 } 00154 /* $$ 00155 00156 $head sign$$ 00157 The following defines the $code CppAD::sign$$ function that 00158 is required to use $code AD<double>$$: 00159 $codep */ 00160 namespace CppAD { 00161 inline double sign(const double& x) 00162 { if( x > 0. ) 00163 return 1.; 00164 if( x == 0. ) 00165 return 0.; 00166 return -1.; 00167 } 00168 } 00169 /* $$ 00170 00171 $head pow $$ 00172 The following defines a $code CppAD::pow$$ function that 00173 is required to use $code AD<double>$$: 00174 $codep */ 00175 namespace CppAD { 00176 inline double pow(const double& x, const double& y) 00177 { return std::pow(x, y); } 00178 } 00179 /*$$ 00180 00181 $head limits$$ 00182 The following defines the numeric limits functions 00183 $code epsilon$$, $code min$$, and $code max$$ for the type 00184 $code double$$. 00185 It also defines the deprecated $code epsilon$$ function: 00186 $codep */ 00187 namespace CppAD { 00188 template <> 00189 class numeric_limits<double> { 00190 public: 00191 // machine epsilon 00192 static double epsilon(void) 00193 { return std::numeric_limits<double>::epsilon(); } 00194 // minimum positive normalized value 00195 static double min(void) 00196 { return std::numeric_limits<double>::min(); } 00197 // maximum finite value 00198 static double max(void) 00199 { return std::numeric_limits<double>::max(); } 00200 }; 00201 // deprecated machine epsilon 00202 template <> 00203 inline double epsilon<double>(void) 00204 { return numeric_limits<double>::epsilon(); } 00205 } 00206 /* $$ 00207 $end 00208 */ 00209 00210 # endif