File indexing completed on 2025-01-18 09:40:08
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>(
0044 function,
0045 "atanh requires x >= -1, but got x = %1%.", x, pol);
0046 }
0047 else if(x > 1)
0048 {
0049 return policies::raise_domain_error<T>(
0050 function,
0051 "atanh requires x <= 1, but got x = %1%.", x, pol);
0052 }
0053 else if((boost::math::isnan)(x))
0054 {
0055 return policies::raise_domain_error<T>(
0056 function,
0057 "atanh requires -1 <= x <= 1, but got x = %1%.", x, pol);
0058 }
0059 else if(x < -1 + tools::epsilon<T>())
0060 {
0061
0062 return -policies::raise_overflow_error<T>(function, nullptr, pol);
0063 }
0064 else if(x > 1 - tools::epsilon<T>())
0065 {
0066
0067 return policies::raise_overflow_error<T>(function, nullptr, pol);
0068 }
0069 else if(abs(x) >= tools::forth_root_epsilon<T>())
0070 {
0071
0072 if(abs(x) < 0.5f)
0073 return (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2;
0074 return(log( (1 + x) / (1 - x) ) / 2);
0075 }
0076 else
0077 {
0078
0079
0080 T result = x;
0081
0082 if (abs(x) >= tools::root_epsilon<T>())
0083 {
0084 T x3 = x*x*x;
0085
0086
0087 result += x3/static_cast<T>(3);
0088 }
0089
0090 return(result);
0091 }
0092 }
0093 }
0094
0095 template<typename T, typename Policy>
0096 inline typename tools::promote_args<T>::type atanh(T x, const Policy&)
0097 {
0098 typedef typename tools::promote_args<T>::type result_type;
0099 typedef typename policies::evaluation<result_type, Policy>::type value_type;
0100 typedef typename policies::normalise<
0101 Policy,
0102 policies::promote_float<false>,
0103 policies::promote_double<false>,
0104 policies::discrete_quantile<>,
0105 policies::assert_undefined<> >::type forwarding_policy;
0106 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
0107 detail::atanh_imp(static_cast<value_type>(x), forwarding_policy()),
0108 "boost::math::atanh<%1%>(%1%)");
0109 }
0110 template<typename T>
0111 inline typename tools::promote_args<T>::type atanh(T x)
0112 {
0113 return boost::math::atanh(x, policies::policy<>());
0114 }
0115
0116 }
0117 }
0118
0119 #endif
0120
0121
0122