comparison DEPENDENCIES/generic/include/boost/math/special_functions/atanh.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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 #if defined(__GNUC__) && (__GNUC__ < 3)
35 // gcc 2.x ignores function scope using declarations,
36 // put them in the scope of the enclosing namespace instead:
37
38 using ::std::abs;
39 using ::std::sqrt;
40 using ::std::log;
41
42 using ::std::numeric_limits;
43 #endif
44
45 // This is the main fare
46
47 template<typename T, typename Policy>
48 inline T atanh_imp(const T x, const Policy& pol)
49 {
50 BOOST_MATH_STD_USING
51 static const char* function = "boost::math::atanh<%1%>(%1%)";
52
53 if(x < -1)
54 {
55 return policies::raise_domain_error<T>(
56 function,
57 "atanh requires x >= -1, but got x = %1%.", x, pol);
58 }
59 else if(x > 1)
60 {
61 return policies::raise_domain_error<T>(
62 function,
63 "atanh requires x <= 1, but got x = %1%.", x, pol);
64 }
65 else if(x < -1 + tools::epsilon<T>())
66 {
67 // -Infinity:
68 return -policies::raise_overflow_error<T>(function, 0, pol);
69 }
70 else if(x > 1 - tools::epsilon<T>())
71 {
72 // Infinity:
73 return policies::raise_overflow_error<T>(function, 0, pol);
74 }
75 else if(abs(x) >= tools::forth_root_epsilon<T>())
76 {
77 // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/
78 if(abs(x) < 0.5f)
79 return (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2;
80 return(log( (1 + x) / (1 - x) ) / 2);
81 }
82 else
83 {
84 // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/06/01/03/01/
85 // approximation by taylor series in x at 0 up to order 2
86 T result = x;
87
88 if (abs(x) >= tools::root_epsilon<T>())
89 {
90 T x3 = x*x*x;
91
92 // approximation by taylor series in x at 0 up to order 4
93 result += x3/static_cast<T>(3);
94 }
95
96 return(result);
97 }
98 }
99 }
100
101 template<typename T, typename Policy>
102 inline typename tools::promote_args<T>::type atanh(T x, const Policy&)
103 {
104 typedef typename tools::promote_args<T>::type result_type;
105 typedef typename policies::evaluation<result_type, Policy>::type value_type;
106 typedef typename policies::normalise<
107 Policy,
108 policies::promote_float<false>,
109 policies::promote_double<false>,
110 policies::discrete_quantile<>,
111 policies::assert_undefined<> >::type forwarding_policy;
112 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
113 detail::atanh_imp(static_cast<value_type>(x), forwarding_policy()),
114 "boost::math::atanh<%1%>(%1%)");
115 }
116 template<typename T>
117 inline typename tools::promote_args<T>::type atanh(T x)
118 {
119 return boost::math::atanh(x, policies::policy<>());
120 }
121
122 }
123 }
124
125 #endif /* BOOST_ATANH_HPP */
126
127
128