]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/include/boost/math/special_functions/atanh.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / include / boost / math / special_functions / atanh.hpp
1 // boost atanh.hpp header file
2
3 // (C) Copyright Hubert Holin 2001.
4 // (C) Copyright John Maddock 2008.
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 // See http://www.boost.org for updates, documentation, and revision history.
10
11 #ifndef BOOST_ATANH_HPP
12 #define BOOST_ATANH_HPP
13
14 #ifdef _MSC_VER
15 #pragma once
16 #endif
17
18
19 #include <boost/config/no_tr1/cmath.hpp>
20 #include <boost/config.hpp>
21 #include <boost/math/tools/precision.hpp>
22 #include <boost/math/policies/error_handling.hpp>
23 #include <boost/math/special_functions/math_fwd.hpp>
24 #include <boost/math/special_functions/log1p.hpp>
25
26 // This is the inverse of the hyperbolic tangent function.
27
28 namespace boost
29 {
30 namespace math
31 {
32 namespace detail
33 {
34 // This is the main fare
35
36 template<typename T, typename Policy>
37 inline T atanh_imp(const T x, const Policy& pol)
38 {
39 BOOST_MATH_STD_USING
40 static const char* function = "boost::math::atanh<%1%>(%1%)";
41
42 if(x < -1)
43 {
44 return policies::raise_domain_error<T>(
45 function,
46 "atanh requires x >= -1, but got x = %1%.", x, pol);
47 }
48 else if(x > 1)
49 {
50 return policies::raise_domain_error<T>(
51 function,
52 "atanh requires x <= 1, but got x = %1%.", x, pol);
53 }
54 else if(x < -1 + tools::epsilon<T>())
55 {
56 // -Infinity:
57 return -policies::raise_overflow_error<T>(function, 0, pol);
58 }
59 else if(x > 1 - tools::epsilon<T>())
60 {
61 // Infinity:
62 return policies::raise_overflow_error<T>(function, 0, pol);
63 }
64 else if(abs(x) >= tools::forth_root_epsilon<T>())
65 {
66 // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/
67 if(abs(x) < 0.5f)
68 return (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2;
69 return(log( (1 + x) / (1 - x) ) / 2);
70 }
71 else
72 {
73 // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/06/01/03/01/
74 // approximation by taylor series in x at 0 up to order 2
75 T result = x;
76
77 if (abs(x) >= tools::root_epsilon<T>())
78 {
79 T x3 = x*x*x;
80
81 // approximation by taylor series in x at 0 up to order 4
82 result += x3/static_cast<T>(3);
83 }
84
85 return(result);
86 }
87 }
88 }
89
90 template<typename T, typename Policy>
91 inline typename tools::promote_args<T>::type atanh(T x, const Policy&)
92 {
93 typedef typename tools::promote_args<T>::type result_type;
94 typedef typename policies::evaluation<result_type, Policy>::type value_type;
95 typedef typename policies::normalise<
96 Policy,
97 policies::promote_float<false>,
98 policies::promote_double<false>,
99 policies::discrete_quantile<>,
100 policies::assert_undefined<> >::type forwarding_policy;
101 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
102 detail::atanh_imp(static_cast<value_type>(x), forwarding_policy()),
103 "boost::math::atanh<%1%>(%1%)");
104 }
105 template<typename T>
106 inline typename tools::promote_args<T>::type atanh(T x)
107 {
108 return boost::math::atanh(x, policies::policy<>());
109 }
110
111 }
112 }
113
114 #endif /* BOOST_ATANH_HPP */
115
116
117