Automatic Differentiation
 
Loading...
Searching...
No Matches
log1m_exp.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_LOG1M_EXP_HPP
2#define STAN_MATH_PRIM_FUN_LOG1M_EXP_HPP
3
11#include <cmath>
12
13namespace stan {
14namespace math {
15
47inline double log1m_exp(double a) {
48 using std::exp;
49 using std::log;
50 if (a > 0) {
51 return NOT_A_NUMBER;
52 } else if (a > -0.693147) {
53 return log(-expm1(a)); // 0.693147 ~= log(2)
54 } else {
55 return log1m(exp(a));
56 }
57}
58
67 template <typename T>
68 static inline auto fun(const T& x) {
69 return log1m_exp(x);
70 }
71};
72
80template <
81 typename T, require_not_var_matrix_t<T>* = nullptr,
83inline auto log1m_exp(const T& x) {
85}
86
87} // namespace math
88} // namespace stan
89
90#endif
require_all_not_t< is_nonscalar_prim_or_rev_kernel_expression< std::decay_t< Types > >... > require_all_not_nonscalar_prim_or_rev_kernel_expression_t
Require none of the types satisfy is_nonscalar_prim_or_rev_kernel_expression.
require_not_t< is_var_matrix< std::decay_t< T > > > require_not_var_matrix_t
Require type does not satisfy is_var_matrix.
static constexpr double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition constants.hpp:56
fvar< T > expm1(const fvar< T > &x)
Definition expm1.hpp:14
fvar< T > log1m_exp(const fvar< T > &x)
Return the natural logarithm of one minus the exponentiation of the specified argument.
Definition log1m_exp.hpp:22
fvar< T > log(const fvar< T > &x)
Definition log.hpp:18
fvar< T > log1m(const fvar< T > &x)
Definition log1m.hpp:12
fvar< T > exp(const fvar< T > &x)
Definition exp.hpp:15
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...
static auto fun(const T &x)
Definition log1m_exp.hpp:68
Structure to wrap log1m_exp() so it can be vectorized.
Definition log1m_exp.hpp:66