| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
log1p.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_LOG1P_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_LOG1P_HPP
3
4 #include <boost/math/tools/promotion.hpp>
5 #include <limits>
6
7 namespace stan {
8 namespace math {
9
37 template <typename T>
38 inline typename boost::math::tools::promote_args<T>::type
39 log1p(const T x) {
40 using std::log;
41 if (!(x >= -1.0))
42 return std::numeric_limits<double>::quiet_NaN();
43
44 if (x > 1e-9 || x < -1e-9)
45 return log(1.0 + x); // direct, if distant from 1
46 else if (x > 1e-16 || x < -1e-16)
47 return x - 0.5 * x * x; // 2nd order Taylor, if close to 1
48 else
49 return x; // 1st order Taylor, if very close to 1
50 }
51
52 }
53 }
54
55 #endif
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
stan::math::e
double e()
Return the base of the natural logarithm.
Definition: constants.hpp:95
stan::math::log1p
fvar< T > log1p(const fvar< T > &x)
Definition: log1p.hpp:16

[ Stan Home Page ] © 2011–2015, Stan Development Team.