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