Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
log1m_exp.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__FUNCTIONS__LOG1M_EXP_HPP
2 #define STAN__MATH__FUNCTIONS__LOG1M_EXP_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
5 #include <stdexcept>
6 #include <boost/throw_exception.hpp>
7 #include <boost/math/special_functions/expm1.hpp>
9 
10 namespace stan {
11  namespace math {
12 
38  template <typename T>
39  inline typename boost::math::tools::promote_args<T>::type
40  log1m_exp(const T a) {
41  if (a >= 0)
42  return std::numeric_limits<double>::quiet_NaN();
43  else if (a > -0.693147)
44  return std::log(-boost::math::expm1(a)); //0.693147 is approximatelly equal to log(2)
45  else
46  return log1m(std::exp(a));
47  }
48 
49  }
50 }
51 
52 #endif
fvar< T > expm1(const fvar< T > &x)
Definition: expm1.hpp:15
boost::math::tools::promote_args< T >::type log1m_exp(const T a)
Calculates the log of 1 minus the exponential of the specified value without overflow log1m_exp(x) = ...
Definition: log1m_exp.hpp:40
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:16
boost::math::tools::promote_args< T >::type log1m(T x)
Return the natural logarithm of one minus the specified value.
Definition: log1m.hpp:40

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