CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
base_float.hpp
Go to the documentation of this file.
1 // $Id$
2 # ifndef CPPAD_CORE_BASE_FLOAT_HPP
3 # define CPPAD_CORE_BASE_FLOAT_HPP
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 # include <cppad/configure.hpp>
15 # include <limits>
16 
17 /*
18 $begin base_float.hpp$$
19 $spell
20  namespaces
21  cppad
22  hpp
23  azmul
24  expm1
25  atanh
26  acosh
27  asinh
28  erf
29  endif
30  abs_geq
31  acos
32  asin
33  atan
34  cos
35  sqrt
36  tanh
37  std
38  fabs
39  bool
40  Lt Le Eq Ge Gt
41  Rel
42  CppAD
43  CondExpOp
44  namespace
45  inline
46  enum
47  const
48  exp
49  const
50 $$
51 
52 
53 $section Enable use of AD<Base> where Base is float$$
54 
55 $head CondExpOp$$
56 The type $code float$$ is a relatively simple type that supports
57 $code <$$, $code <=$$, $code ==$$, $code >=$$, and $code >$$ operators; see
58 $cref/ordered type/base_cond_exp/CondExpTemplate/Ordered Type/$$.
59 Hence its $code CondExpOp$$ function is defined by
60 $srccode%cpp% */
61 namespace CppAD {
62  inline float CondExpOp(
63  enum CompareOp cop ,
64  const float& left ,
65  const float& right ,
66  const float& exp_if_true ,
67  const float& exp_if_false )
68  { return CondExpTemplate(cop, left, right, exp_if_true, exp_if_false);
69  }
70 }
71 /* %$$
72 
73 $head CondExpRel$$
74 The $cref/CPPAD_COND_EXP_REL/base_cond_exp/CondExpRel/$$ macro invocation
75 $srccode%cpp% */
76 namespace CppAD {
77  CPPAD_COND_EXP_REL(float)
78 }
79 /* %$$
80 uses $code CondExpOp$$ above to
81 define $codei%CondExp%Rel%$$ for $code float$$ arguments
82 and $icode%Rel%$$ equal to
83 $code Lt$$, $code Le$$, $code Eq$$, $code Ge$$, and $code Gt$$.
84 
85 $head EqualOpSeq$$
86 The type $code float$$ is simple (in this respect) and so we define
87 $srccode%cpp% */
88 namespace CppAD {
89  inline bool EqualOpSeq(const float& x, const float& y)
90  { return x == y; }
91 }
92 /* %$$
93 
94 $head Identical$$
95 The type $code float$$ is simple (in this respect) and so we define
96 $srccode%cpp% */
97 namespace CppAD {
98  inline bool IdenticalPar(const float& x)
99  { return true; }
100  inline bool IdenticalZero(const float& x)
101  { return (x == 0.f); }
102  inline bool IdenticalOne(const float& x)
103  { return (x == 1.f); }
104  inline bool IdenticalEqualPar(const float& x, const float& y)
105  { return (x == y); }
106 }
107 /* %$$
108 
109 $head Integer$$
110 $srccode%cpp% */
111 namespace CppAD {
112  inline int Integer(const float& x)
113  { return static_cast<int>(x); }
114 }
115 /* %$$
116 
117 $head azmul$$
118 $srccode%cpp% */
119 namespace CppAD {
120  CPPAD_AZMUL( float )
121 }
122 /* %$$
123 
124 $head Ordered$$
125 The $code float$$ type supports ordered comparisons
126 $srccode%cpp% */
127 namespace CppAD {
128  inline bool GreaterThanZero(const float& x)
129  { return x > 0.f; }
130  inline bool GreaterThanOrZero(const float& x)
131  { return x >= 0.f; }
132  inline bool LessThanZero(const float& x)
133  { return x < 0.f; }
134  inline bool LessThanOrZero(const float& x)
135  { return x <= 0.f; }
136  inline bool abs_geq(const float& x, const float& y)
137  { return std::fabs(x) >= std::fabs(y); }
138 }
139 /* %$$
140 
141 $head Unary Standard Math$$
142 The following macro invocations import the $code float$$ versions of
143 the unary standard math functions into the $code CppAD$$ namespace.
144 Importing avoids ambiguity errors when using both the
145 $code CppAD$$ and $code std$$ namespaces.
146 Note this also defines the $cref/double/base_double.hpp/Unary Standard Math/$$
147 versions of these functions.
148 $srccode%cpp% */
149 namespace CppAD {
150  using std::acos;
151  using std::asin;
152  using std::atan;
153  using std::cos;
154  using std::cosh;
155  using std::exp;
156  using std::fabs;
157  using std::log;
158  using std::log10;
159  using std::sin;
160  using std::sinh;
161  using std::sqrt;
162  using std::tan;
163  using std::tanh;
164 # if CPPAD_USE_CPLUSPLUS_2011
165  using std::erf;
166  using std::asinh;
167  using std::acosh;
168  using std::atanh;
169  using std::expm1;
170  using std::log1p;
171 # endif
172 }
173 
174 /* %$$
175 The absolute value function is special because its $code std$$ name is
176 $code fabs$$
177 $srccode%cpp% */
178 namespace CppAD {
179  inline float abs(const float& x)
180  { return std::fabs(x); }
181 }
182 /* %$$
183 
184 $head sign$$
185 The following defines the $code CppAD::sign$$ function that
186 is required to use $code AD<float>$$:
187 $srccode%cpp% */
188 namespace CppAD {
189  inline float sign(const float& x)
190  { if( x > 0.f )
191  return 1.f;
192  if( x == 0.f )
193  return 0.f;
194  return -1.f;
195  }
196 }
197 /* %$$
198 $head pow$$
199 The following defines a $code CppAD::pow$$ function that
200 is required to use $code AD<float>$$.
201 As with the unary standard math functions,
202 this has the exact same signature as $code std::pow$$,
203 so use it instead of defining another function.
204 $srccode%cpp% */
205 namespace CppAD {
206  using std::pow;
207 }
208 /* %$$
209 
210 $head numeric_limits$$
211 The following defines the CppAD $cref numeric_limits$$
212 for the type $code float$$:
213 $srccode%cpp% */
214 namespace CppAD {
215  CPPAD_NUMERIC_LIMITS(float, float)
216 }
217 /* %$$
218 
219 $head to_string$$
220 There is no need to define $code to_string$$ for $code float$$
221 because it is defined by including $code cppad/utility/to_string.hpp$$;
222 see $cref to_string$$.
223 See $cref/base_complex.hpp/base_complex.hpp/to_string/$$ for an example where
224 it is necessary to define $code to_string$$ for a $icode Base$$ type.
225 
226 $end
227 */
228 
229 
230 # endif
std::complex< double > erf(const std::complex< double > &x)
AD< Base > cosh(const AD< Base > &x)
AD< Base > log(const AD< Base > &x)
std::complex< double > atan(const std::complex< double > &x)
AD< Base > sinh(const AD< Base > &x)
bool GreaterThanOrZero(const std::complex< double > &x)
ResultType CondExpTemplate(enum CompareOp cop, const CompareType &left, const CompareType &right, const ResultType &exp_if_true, const ResultType &exp_if_false)
Template function to implement Conditional Expressions for simple types that have comparision operato...
#define CPPAD_AZMUL(Base)
AD< Base > abs(const AD< Base > &x)
Definition: abs.hpp:105
std::complex< double > acos(const std::complex< double > &x)
bool IdenticalPar(const std::complex< double > &x)
AD< Base > tan(const AD< Base > &x)
bool EqualOpSeq(const std::complex< double > &x, const std::complex< double > &y)
bool IdenticalZero(const std::complex< double > &x)
AD< Base > exp(const AD< Base > &x)
AD< Base > log10(const AD< Base > &x)
Compute the log of base 10 of x where has type AD&lt;Base&gt;
std::complex< double > asinh(const std::complex< double > &x)
bool abs_geq(const std::complex< double > &x, const std::complex< double > &y)
std::complex< double > acosh(const std::complex< double > &x)
Type pow(const Type &x, const int &n)
Definition: pow_int.hpp:116
bool LessThanOrZero(const std::complex< double > &x)
std::complex< double > expm1(const std::complex< double > &x)
AD< Base > sqrt(const AD< Base > &x)
AD< Base > tanh(const AD< Base > &x)
#define CPPAD_NUMERIC_LIMITS(Other, Base)
Definition: base_limits.hpp:49
std::complex< double > atanh(const std::complex< double > &x)
AD< Base > sin(const AD< Base > &x)
std::complex< double > sign(const std::complex< double > &x)
bool IdenticalEqualPar(const std::complex< double > &x, const std::complex< double > &y)
AD< Base > cos(const AD< Base > &x)
bool IdenticalOne(const std::complex< double > &x)
std::complex< double > asin(const std::complex< double > &x)
int Integer(const std::complex< double > &x)
bool LessThanZero(const std::complex< double > &x)
#define CPPAD_COND_EXP_REL(Type)
The macro defines the operations.
std::complex< double > CondExpOp(enum CppAD::CompareOp cop, const std::complex< double > &left, const std::complex< double > &right, const std::complex< double > &trueCase, const std::complex< double > &falseCase)
std::complex< double > fabs(const std::complex< double > &x)
bool GreaterThanZero(const std::complex< double > &x)
std::complex< double > log1p(const std::complex< double > &x)