File indexing completed on 2025-07-14 08:36:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASINH_HPP
0012 #define BOOST_ASINH_HPP
0013
0014 #ifdef _MSC_VER
0015 #pragma once
0016 #endif
0017
0018
0019 #include <cmath>
0020 #include <boost/math/tools/precision.hpp>
0021 #include <boost/math/special_functions/math_fwd.hpp>
0022 #include <boost/math/special_functions/sqrt1pm1.hpp>
0023 #include <boost/math/special_functions/log1p.hpp>
0024 #include <boost/math/constants/constants.hpp>
0025 #include <boost/math/special_functions/fpclassify.hpp>
0026
0027
0028
0029 namespace boost
0030 {
0031 namespace math
0032 {
0033 namespace detail{
0034 template<typename T, class Policy>
0035 inline T asinh_imp(const T x, const Policy& pol)
0036 {
0037 BOOST_MATH_STD_USING
0038
0039 if((boost::math::isnan)(x))
0040 {
0041 return policies::raise_domain_error<T>("boost::math::asinh<%1%>(%1%)", "asinh requires a finite argument, but got x = %1%.", x, pol);
0042 }
0043 if (x >= tools::forth_root_epsilon<T>())
0044 {
0045 if (x > 1 / tools::root_epsilon<T>())
0046 {
0047
0048
0049 return constants::ln_two<T>() + log(x) + 1/ (4 * x * x);
0050 }
0051 else if(x < 0.5f)
0052 {
0053
0054 return boost::math::log1p(x + boost::math::sqrt1pm1(x * x, pol), pol);
0055 }
0056 else
0057 {
0058
0059 return( log( x + sqrt(x*x+1) ) );
0060 }
0061 }
0062 else if (x <= -tools::forth_root_epsilon<T>())
0063 {
0064 return(-asinh(-x, pol));
0065 }
0066 else
0067 {
0068
0069
0070 T result = x;
0071
0072 if (abs(x) >= tools::root_epsilon<T>())
0073 {
0074 T x3 = x*x*x;
0075
0076
0077 result -= x3/static_cast<T>(6);
0078 }
0079
0080 return(result);
0081 }
0082 }
0083 }
0084
0085 template<typename T>
0086 inline typename tools::promote_args<T>::type asinh(T x)
0087 {
0088 return boost::math::asinh(x, policies::policy<>());
0089 }
0090 template<typename T, typename Policy>
0091 inline typename tools::promote_args<T>::type asinh(T x, const Policy&)
0092 {
0093 typedef typename tools::promote_args<T>::type result_type;
0094 typedef typename policies::evaluation<result_type, Policy>::type value_type;
0095 typedef typename policies::normalise<
0096 Policy,
0097 policies::promote_float<false>,
0098 policies::promote_double<false>,
0099 policies::discrete_quantile<>,
0100 policies::assert_undefined<> >::type forwarding_policy;
0101 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
0102 detail::asinh_imp(static_cast<value_type>(x), forwarding_policy()),
0103 "boost::math::asinh<%1%>(%1%)");
0104 }
0105
0106 }
0107 }
0108
0109 #endif
0110