1#ifndef STAN_MATH_PRIM_FUN_LOG_COSH_HPP
2#define STAN_MATH_PRIM_FUN_LOG_COSH_HPP
25template <
typename T, require_arithmetic_t<T>* =
nullptr>
27 const double abs_x =
fabs(
static_cast<double>(x));
29 const double expm1_abs_x =
expm1(abs_x);
30 return log1p(expm1_abs_x * expm1_abs_x / (2.0 * (1.0 + expm1_abs_x)));
32 const double exp_neg_abs_x =
exp(-abs_x);
33 return abs_x +
log1p(0.5 * (exp_neg_abs_x * exp_neg_abs_x - 1.0));
48 static inline auto fun(
const T& x) {
60template <
typename T, require_container_t<T>* =
nullptr,
61 require_not_var_matrix_t<T>* =
nullptr,
62 require_not_nonscalar_prim_or_rev_kernel_expression_t<T>* =
nullptr>
fvar< T > expm1(const fvar< T > &x)
fvar< T > log1p(const fvar< T > &x)
fvar< T > log_cosh(const fvar< T > &x)
Return the natural logarithm of the hyperbolic cosine of the argument.
fvar< T > fabs(const fvar< T > &x)
fvar< T > exp(const fvar< T > &x)
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)
Return the natural logarithm of the hyperbolic cosine of the argument.
Structure to wrap log_cosh() so it can be vectorized.