Chris@16
|
1 // boost asinh.hpp header file
|
Chris@16
|
2
|
Chris@16
|
3 // (C) Copyright Eric Ford & Hubert Holin 2001.
|
Chris@16
|
4 // (C) Copyright John Maddock 2008.
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
6 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 // See http://www.boost.org for updates, documentation, and revision history.
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASINH_HPP
|
Chris@16
|
12 #define BOOST_ASINH_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #ifdef _MSC_VER
|
Chris@16
|
15 #pragma once
|
Chris@16
|
16 #endif
|
Chris@16
|
17
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/config/no_tr1/cmath.hpp>
|
Chris@16
|
20 #include <boost/config.hpp>
|
Chris@16
|
21 #include <boost/math/tools/precision.hpp>
|
Chris@16
|
22 #include <boost/math/special_functions/math_fwd.hpp>
|
Chris@16
|
23 #include <boost/math/special_functions/sqrt1pm1.hpp>
|
Chris@16
|
24 #include <boost/math/special_functions/log1p.hpp>
|
Chris@16
|
25 #include <boost/math/constants/constants.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 // This is the inverse of the hyperbolic sine function.
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost
|
Chris@16
|
30 {
|
Chris@16
|
31 namespace math
|
Chris@16
|
32 {
|
Chris@16
|
33 namespace detail{
|
Chris@16
|
34 template<typename T, class Policy>
|
Chris@16
|
35 inline T asinh_imp(const T x, const Policy& pol)
|
Chris@16
|
36 {
|
Chris@16
|
37 BOOST_MATH_STD_USING
|
Chris@16
|
38
|
Chris@16
|
39 if (x >= tools::forth_root_epsilon<T>())
|
Chris@16
|
40 {
|
Chris@16
|
41 if (x > 1 / tools::root_epsilon<T>())
|
Chris@16
|
42 {
|
Chris@16
|
43 // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/06/01/0001/
|
Chris@16
|
44 // approximation by laurent series in 1/x at 0+ order from -1 to 1
|
Chris@16
|
45 return constants::ln_two<T>() + log(x) + 1/ (4 * x * x);
|
Chris@16
|
46 }
|
Chris@16
|
47 else if(x < 0.5f)
|
Chris@16
|
48 {
|
Chris@16
|
49 // As below, but rearranged to preserve digits:
|
Chris@16
|
50 return boost::math::log1p(x + boost::math::sqrt1pm1(x * x, pol), pol);
|
Chris@16
|
51 }
|
Chris@16
|
52 else
|
Chris@16
|
53 {
|
Chris@16
|
54 // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/
|
Chris@16
|
55 return( log( x + sqrt(x*x+1) ) );
|
Chris@16
|
56 }
|
Chris@16
|
57 }
|
Chris@16
|
58 else if (x <= -tools::forth_root_epsilon<T>())
|
Chris@16
|
59 {
|
Chris@16
|
60 return(-asinh(-x, pol));
|
Chris@16
|
61 }
|
Chris@16
|
62 else
|
Chris@16
|
63 {
|
Chris@16
|
64 // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/03/01/0001/
|
Chris@16
|
65 // approximation by taylor series in x at 0 up to order 2
|
Chris@16
|
66 T result = x;
|
Chris@16
|
67
|
Chris@16
|
68 if (abs(x) >= tools::root_epsilon<T>())
|
Chris@16
|
69 {
|
Chris@16
|
70 T x3 = x*x*x;
|
Chris@16
|
71
|
Chris@16
|
72 // approximation by taylor series in x at 0 up to order 4
|
Chris@16
|
73 result -= x3/static_cast<T>(6);
|
Chris@16
|
74 }
|
Chris@16
|
75
|
Chris@16
|
76 return(result);
|
Chris@16
|
77 }
|
Chris@16
|
78 }
|
Chris@16
|
79 }
|
Chris@16
|
80
|
Chris@16
|
81 template<typename T>
|
Chris@16
|
82 inline typename tools::promote_args<T>::type asinh(T x)
|
Chris@16
|
83 {
|
Chris@16
|
84 return boost::math::asinh(x, policies::policy<>());
|
Chris@16
|
85 }
|
Chris@16
|
86 template<typename T, typename Policy>
|
Chris@16
|
87 inline typename tools::promote_args<T>::type asinh(T x, const Policy&)
|
Chris@16
|
88 {
|
Chris@16
|
89 typedef typename tools::promote_args<T>::type result_type;
|
Chris@16
|
90 typedef typename policies::evaluation<result_type, Policy>::type value_type;
|
Chris@16
|
91 typedef typename policies::normalise<
|
Chris@16
|
92 Policy,
|
Chris@16
|
93 policies::promote_float<false>,
|
Chris@16
|
94 policies::promote_double<false>,
|
Chris@16
|
95 policies::discrete_quantile<>,
|
Chris@16
|
96 policies::assert_undefined<> >::type forwarding_policy;
|
Chris@16
|
97 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
|
Chris@16
|
98 detail::asinh_imp(static_cast<value_type>(x), forwarding_policy()),
|
Chris@16
|
99 "boost::math::asinh<%1%>(%1%)");
|
Chris@16
|
100 }
|
Chris@16
|
101
|
Chris@16
|
102 }
|
Chris@16
|
103 }
|
Chris@16
|
104
|
Chris@16
|
105 #endif /* BOOST_ASINH_HPP */
|
Chris@16
|
106
|