Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
log1m_exp.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_LOG1M_EXP_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_LOG1M_EXP_HPP
3 
5 #include <boost/math/tools/promotion.hpp>
6 #include <boost/throw_exception.hpp>
7 #include <cmath>
8 #include <limits>
9 #include <stdexcept>
10 
11 namespace stan {
12  namespace math {
13 
39  template <typename T>
40  inline typename boost::math::tools::promote_args<T>::type
41  log1m_exp(const T a) {
42  using std::log;
43  using std::exp;
45 
46  if (a >= 0)
47  return std::numeric_limits<double>::quiet_NaN();
48  else if (a > -0.693147)
49  return log(-expm1(a)); // 0.693147 ~= log(2)
50  else
51  return log1m(exp(a));
52  }
53 
54  }
55 }
56 
57 #endif
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
fvar< T > expm1(const fvar< T > &x)
Definition: expm1.hpp:12
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
fvar< T > log1m_exp(const fvar< T > &x)
Definition: log1m_exp.hpp:16
fvar< T > log1m(const fvar< T > &x)
Definition: log1m.hpp:16

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