annotate DEPENDENCIES/generic/include/boost/math/special_functions/acosh.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // boost asinh.hpp header file
Chris@16 2
Chris@16 3 // (C) Copyright Eric Ford 2001 & Hubert Holin.
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_ACOSH_HPP
Chris@16 12 #define BOOST_ACOSH_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 #include <boost/config/no_tr1/cmath.hpp>
Chris@16 19 #include <boost/config.hpp>
Chris@16 20 #include <boost/math/tools/precision.hpp>
Chris@16 21 #include <boost/math/policies/error_handling.hpp>
Chris@16 22 #include <boost/math/special_functions/math_fwd.hpp>
Chris@16 23 #include <boost/math/special_functions/log1p.hpp>
Chris@16 24 #include <boost/math/constants/constants.hpp>
Chris@16 25
Chris@16 26 // This is the inverse of the hyperbolic cosine function.
Chris@16 27
Chris@16 28 namespace boost
Chris@16 29 {
Chris@16 30 namespace math
Chris@16 31 {
Chris@16 32 namespace detail
Chris@16 33 {
Chris@16 34 template<typename T, typename Policy>
Chris@16 35 inline T acosh_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 < 1)
Chris@16 40 {
Chris@16 41 return policies::raise_domain_error<T>(
Chris@16 42 "boost::math::acosh<%1%>(%1%)",
Chris@16 43 "acosh requires x >= 1, but got x = %1%.", x, pol);
Chris@16 44 }
Chris@16 45 else if ((x - 1) >= tools::root_epsilon<T>())
Chris@16 46 {
Chris@16 47 if (x > 1 / tools::root_epsilon<T>())
Chris@16 48 {
Chris@16 49 // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/06/01/0001/
Chris@16 50 // approximation by laurent series in 1/x at 0+ order from -1 to 0
Chris@16 51 return log(x) + constants::ln_two<T>();
Chris@16 52 }
Chris@16 53 else if(x < 1.5f)
Chris@16 54 {
Chris@16 55 // This is just a rearrangement of the standard form below
Chris@16 56 // devised to minimse loss of precision when x ~ 1:
Chris@16 57 T y = x - 1;
Chris@16 58 return boost::math::log1p(y + sqrt(y * y + 2 * y), pol);
Chris@16 59 }
Chris@16 60 else
Chris@16 61 {
Chris@16 62 // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/
Chris@16 63 return( log( x + sqrt(x * x - 1) ) );
Chris@16 64 }
Chris@16 65 }
Chris@16 66 else
Chris@16 67 {
Chris@16 68 // see http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/04/01/0001/
Chris@16 69 T y = x - 1;
Chris@16 70
Chris@16 71 // approximation by taylor series in y at 0 up to order 2
Chris@16 72 T result = sqrt(2 * y) * (1 - y /12 + 3 * y * y / 160);
Chris@16 73 return result;
Chris@16 74 }
Chris@16 75 }
Chris@16 76 }
Chris@16 77
Chris@16 78 template<typename T, typename Policy>
Chris@16 79 inline typename tools::promote_args<T>::type acosh(T x, const Policy&)
Chris@16 80 {
Chris@16 81 typedef typename tools::promote_args<T>::type result_type;
Chris@16 82 typedef typename policies::evaluation<result_type, Policy>::type value_type;
Chris@16 83 typedef typename policies::normalise<
Chris@16 84 Policy,
Chris@16 85 policies::promote_float<false>,
Chris@16 86 policies::promote_double<false>,
Chris@16 87 policies::discrete_quantile<>,
Chris@16 88 policies::assert_undefined<> >::type forwarding_policy;
Chris@16 89 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
Chris@16 90 detail::acosh_imp(static_cast<value_type>(x), forwarding_policy()),
Chris@16 91 "boost::math::acosh<%1%>(%1%)");
Chris@16 92 }
Chris@16 93 template<typename T>
Chris@16 94 inline typename tools::promote_args<T>::type acosh(T x)
Chris@16 95 {
Chris@16 96 return boost::math::acosh(x, policies::policy<>());
Chris@16 97 }
Chris@16 98
Chris@16 99 }
Chris@16 100 }
Chris@16 101
Chris@16 102 #endif /* BOOST_ACOSH_HPP */
Chris@16 103
Chris@16 104