1
// boost asinh.hpp header file
3
// (C) Copyright Eric Ford 2001 & Hubert Holin.
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)
9
// See http://www.boost.org for updates, documentation, and revision history.
11
#ifndef BOOST_ACOSH_HPP
12
#define BOOST_ACOSH_HPP
18
#include <boost/config/no_tr1/cmath.hpp>
19
#include <boost/config.hpp>
20
#include <boost/math/tools/precision.hpp>
21
#include <boost/math/policies/error_handling.hpp>
22
#include <boost/math/special_functions/math_fwd.hpp>
23
#include <boost/math/special_functions/log1p.hpp>
25
// This is the inverse of the hyperbolic cosine function.
33
#if defined(__GNUC__) && (__GNUC__ < 3)
34
// gcc 2.x ignores function scope using declarations,
35
// put them in the scope of the enclosing namespace instead:
41
using ::std::numeric_limits;
44
template<typename T, typename Policy>
45
inline T acosh_imp(const T x, const Policy& pol)
51
return policies::raise_domain_error<T>(
52
"boost::math::acosh<%1%>(%1%)",
53
"acosh requires x >= 1, but got x = %1%.", x, pol);
55
else if ((x - 1) >= tools::root_epsilon<T>())
57
if (x > 1 / tools::root_epsilon<T>())
59
// http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/06/01/0001/
60
// approximation by laurent series in 1/x at 0+ order from -1 to 0
61
return( log( x * 2) );
65
// This is just a rearrangement of the standard form below
66
// devised to minimse loss of precision when x ~ 1:
68
return boost::math::log1p(y + sqrt(y * y + 2 * y), pol);
72
// http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/
73
return( log( x + sqrt(x * x - 1) ) );
78
// see http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/04/01/0001/
81
// approximation by taylor series in y at 0 up to order 2
82
T result = sqrt(2 * y) * (1 + y /12 + 3 * y * y / 160);
88
template<typename T, typename Policy>
89
inline typename tools::promote_args<T>::type acosh(T x, const Policy&)
91
typedef typename tools::promote_args<T>::type result_type;
92
typedef typename policies::evaluation<result_type, Policy>::type value_type;
93
typedef typename policies::normalise<
95
policies::promote_float<false>,
96
policies::promote_double<false>,
97
policies::discrete_quantile<>,
98
policies::assert_undefined<> >::type forwarding_policy;
99
return policies::checked_narrowing_cast<result_type, forwarding_policy>(
100
detail::acosh_imp(static_cast<value_type>(x), forwarding_policy()),
101
"boost::math::acosh<%1%>(%1%)");
104
inline typename tools::promote_args<T>::type acosh(T x)
106
return boost::math::acosh(x, policies::policy<>());
112
#endif /* BOOST_ACOSH_HPP */