File indexing completed on 2025-07-09 08:15:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ATANH_HPP
0012 #define BOOST_ATANH_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/special_functions/fpclassify.hpp>
0024
0025
0026
0027 namespace boost
0028 {
0029 namespace math
0030 {
0031 namespace detail
0032 {
0033
0034
0035 template<typename T, typename Policy>
0036 inline T atanh_imp(const T x, const Policy& pol)
0037 {
0038 BOOST_MATH_STD_USING
0039 static const char* function = "boost::math::atanh<%1%>(%1%)";
0040
0041 if(x < -1)
0042 {
0043 return policies::raise_domain_error<T>(function, "atanh requires x >= -1, but got x = %1%.", x, pol);
0044 }
0045 else if(x > 1)
0046 {
0047 return policies::raise_domain_error<T>(function, "atanh requires x <= 1, but got x = %1%.", x, pol);
0048 }
0049 else if((boost::math::isnan)(x))
0050 {
0051 return policies::raise_domain_error<T>(function, "atanh requires -1 <= x <= 1, but got x = %1%.", x, pol);
0052 }
0053 else if(x < -1 + tools::epsilon<T>())
0054 {
0055
0056 return -policies::raise_overflow_error<T>(function, nullptr, pol);
0057 }
0058 else if(x > 1 - tools::epsilon<T>())
0059 {
0060
0061 return policies::raise_overflow_error<T>(function, nullptr, pol);
0062 }
0063 else if(abs(x) >= tools::forth_root_epsilon<T>())
0064 {
0065
0066 if(abs(x) < 0.5f)
0067 return (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2;
0068 return(log( (1 + x) / (1 - x) ) / 2);
0069 }
0070 else
0071 {
0072
0073
0074 T result = x;
0075
0076 if (abs(x) >= tools::root_epsilon<T>())
0077 {
0078 T x3 = x*x*x;
0079
0080
0081 result += x3/static_cast<T>(3);
0082 }
0083
0084 return(result);
0085 }
0086 }
0087 }
0088
0089 template<typename T, typename Policy>
0090 inline typename tools::promote_args<T>::type atanh(T x, const Policy&)
0091 {
0092 typedef typename tools::promote_args<T>::type result_type;
0093 typedef typename policies::evaluation<result_type, Policy>::type value_type;
0094 typedef typename policies::normalise<
0095 Policy,
0096 policies::promote_float<false>,
0097 policies::promote_double<false>,
0098 policies::discrete_quantile<>,
0099 policies::assert_undefined<> >::type forwarding_policy;
0100 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
0101 detail::atanh_imp(static_cast<value_type>(x), forwarding_policy()),
0102 "boost::math::atanh<%1%>(%1%)");
0103 }
0104 template<typename T>
0105 inline typename tools::promote_args<T>::type atanh(T x)
0106 {
0107 return boost::math::atanh(x, policies::policy<>());
0108 }
0109
0110 }
0111 }
0112
0113 #endif
0114
0115
0116