Automatic Differentiation
 
Loading...
Searching...
No Matches
acosh.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_ACOSH_HPP
2#define STAN_MATH_PRIM_FUN_ACOSH_HPP
3
12#include <cmath>
13#include <complex>
14
15namespace stan {
16namespace math {
17
26template <typename T, require_arithmetic_t<T>* = nullptr>
27inline double acosh(T&& x) {
28 if (is_nan(x)) {
29 return x;
30 } else {
31 check_greater_or_equal("acosh", "x", x, 1.0);
32#ifdef _WIN32
33 if (is_inf(x))
34 return x;
35#endif
36 return std::acosh(x);
37 }
38}
39
48template <typename T, require_complex_bt<std::is_arithmetic, T>* = nullptr>
49inline auto acosh(T&& x) {
50 return std::acosh(x);
51}
52
56struct acosh_fun {
64 template <typename T>
65 static inline auto fun(T&& x) {
66 return acosh(std::forward<T>(x));
67 }
68};
69
80template <typename T, require_ad_container_t<T>* = nullptr>
81inline auto acosh(T&& x) {
82 return apply_scalar_unary<acosh_fun, T>::apply(std::forward<T>(x));
83}
84
95template <typename Container,
96 require_container_bt<std::is_arithmetic, Container>* = nullptr>
97inline auto acosh(Container&& x) {
99 std::forward<Container>(x));
100}
101
102namespace internal {
103
111template <typename V>
112inline std::complex<V> complex_acosh(const std::complex<V>& z) {
113 std::complex<double> y_d = acosh(value_of_rec(z));
114 auto y = log(z + sqrt(z * z - 1));
115 return copysign(y, y_d);
116}
117
118} // namespace internal
119
120} // namespace math
121} // namespace stan
122
123#endif
double copysign(double a, double_d b)
Definition double_d.hpp:329
std::complex< V > complex_acosh(const std::complex< V > &z)
Return the hyperbolic arc cosine of the complex argument.
Definition acosh.hpp:112
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > acosh(const fvar< T > &x)
Definition acosh.hpp:16
bool is_nan(T &&x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition is_nan.hpp:22
fvar< T > log(const fvar< T > &x)
Definition log.hpp:18
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low, Idxs... idxs)
Throw an exception if y is not greater or equal than low.
fvar< T > sqrt(const fvar< T > &x)
Definition sqrt.hpp:18
int is_inf(const fvar< T > &x)
Returns 1 if the input's value is infinite and 0 otherwise.
Definition is_inf.hpp:21
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
static auto fun(T &&x)
Return the inverse hyperbolic cosine of the specified argument.
Definition acosh.hpp:65
Structure to wrap acosh() so it can be vectorized.
Definition acosh.hpp:56
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...