]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/include/boost/math/special_functions/asinh.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / include / boost / math / special_functions / asinh.hpp
CommitLineData
7c673cae
FG
1// boost asinh.hpp header file
2
3// (C) Copyright Eric Ford & 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_ASINH_HPP
12#define BOOST_ASINH_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/special_functions/math_fwd.hpp>
23#include <boost/math/special_functions/sqrt1pm1.hpp>
24#include <boost/math/special_functions/log1p.hpp>
25#include <boost/math/constants/constants.hpp>
26
27// This is the inverse of the hyperbolic sine function.
28
29namespace boost
30{
31 namespace math
32 {
33 namespace detail{
34 template<typename T, class Policy>
35 inline T asinh_imp(const T x, const Policy& pol)
36 {
37 BOOST_MATH_STD_USING
38
39 if (x >= tools::forth_root_epsilon<T>())
40 {
41 if (x > 1 / tools::root_epsilon<T>())
42 {
43 // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/06/01/0001/
44 // approximation by laurent series in 1/x at 0+ order from -1 to 1
45 return constants::ln_two<T>() + log(x) + 1/ (4 * x * x);
46 }
47 else if(x < 0.5f)
48 {
49 // As below, but rearranged to preserve digits:
50 return boost::math::log1p(x + boost::math::sqrt1pm1(x * x, pol), pol);
51 }
52 else
53 {
54 // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/
55 return( log( x + sqrt(x*x+1) ) );
56 }
57 }
58 else if (x <= -tools::forth_root_epsilon<T>())
59 {
60 return(-asinh(-x, pol));
61 }
62 else
63 {
64 // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/03/01/0001/
65 // approximation by taylor series in x at 0 up to order 2
66 T result = x;
67
68 if (abs(x) >= tools::root_epsilon<T>())
69 {
70 T x3 = x*x*x;
71
72 // approximation by taylor series in x at 0 up to order 4
73 result -= x3/static_cast<T>(6);
74 }
75
76 return(result);
77 }
78 }
79 }
80
81 template<typename T>
82 inline typename tools::promote_args<T>::type asinh(T x)
83 {
84 return boost::math::asinh(x, policies::policy<>());
85 }
86 template<typename T, typename Policy>
87 inline typename tools::promote_args<T>::type asinh(T x, const Policy&)
88 {
89 typedef typename tools::promote_args<T>::type result_type;
90 typedef typename policies::evaluation<result_type, Policy>::type value_type;
91 typedef typename policies::normalise<
92 Policy,
93 policies::promote_float<false>,
94 policies::promote_double<false>,
95 policies::discrete_quantile<>,
96 policies::assert_undefined<> >::type forwarding_policy;
97 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
98 detail::asinh_imp(static_cast<value_type>(x), forwarding_policy()),
99 "boost::math::asinh<%1%>(%1%)");
100 }
101
102 }
103}
104
105#endif /* BOOST_ASINH_HPP */
106