1 #ifndef STAN_MATH_PRIM_FUN_ASINH_HPP 2 #define STAN_MATH_PRIM_FUN_ASINH_HPP 3 4 #include <stan/math/prim/core.hpp> 5 #include <stan/math/prim/meta.hpp> 6 #include <stan/math/prim/fun/abs.hpp> 7 #include <stan/math/prim/fun/arg.hpp> 8 #include <stan/math/prim/fun/copysign.hpp> 9 #include <stan/math/prim/fun/isfinite.hpp> 10 #include <stan/math/prim/fun/isinf.hpp> 11 #include <stan/math/prim/fun/isnan.hpp> 12 #include <stan/math/prim/fun/log.hpp> 13 #include <stan/math/prim/fun/polar.hpp> 14 #include <stan/math/prim/fun/sqrt.hpp> 15 #include <stan/math/prim/fun/value_of_rec.hpp> 16 #include <stan/math/prim/functor/apply_scalar_unary.hpp> 17 #include <cmath> 18 #include <complex> 19 20 namespace stan { 21 namespace math { 22 23 /** 24 * Structure to wrap `asinh()` so it can be vectorized. 25 * 26 * @tparam T argument scalar type 27 * @param x argument 28 * @return inverse hyperbolic sine of argument in radians. 29 */ 30 struct asinh_fun { 31 template <typename T> funstan::math::asinh_fun32 static inline T fun(const T& x) { 33 using std::asinh; 34 return asinh(x); 35 } 36 }; 37 38 /** 39 * Returns the elementwise `asinh()` of the input, 40 * which may be a scalar or any Stan container of numeric scalars. 41 * 42 * @tparam T type of container 43 * @param x container 44 * @return Inverse hyperbolic sine of each value in the container. 45 */ 46 template < 47 typename T, require_not_var_matrix_t<T>* = nullptr, 48 require_all_not_nonscalar_prim_or_rev_kernel_expression_t<T>* = nullptr> asinh(const T & x)49inline auto asinh(const T& x) { 50 return apply_scalar_unary<asinh_fun, T>::apply(x); 51 } 52 53 namespace internal { 54 /** 55 * Return the hyperbolic arc sine of the complex argument. 56 * 57 * @tparam V value type of argument 58 * @param[in] z argument 59 * @return hyperbolic arc sine of the argument 60 */ 61 template <typename V> complex_asinh(const std::complex<V> & z)62inline std::complex<V> complex_asinh(const std::complex<V>& z) { 63 std::complex<double> y_d = asinh(value_of_rec(z)); 64 auto y = log(z + sqrt(1 + z * z)); 65 return copysign(y, y_d); 66 } 67 } // namespace internal 68 69 } // namespace math 70 } // namespace stan 71 72 #endif 73