annotate DEPENDENCIES/generic/include/boost/math/special_functions/acosh.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
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 #if defined(__GNUC__) && (__GNUC__ < 3)
Chris@16 35 // gcc 2.x ignores function scope using declarations,
Chris@16 36 // put them in the scope of the enclosing namespace instead:
Chris@16 37
Chris@16 38 using ::std::abs;
Chris@16 39 using ::std::sqrt;
Chris@16 40 using ::std::log;
Chris@16 41
Chris@16 42 using ::std::numeric_limits;
Chris@16 43 #endif
Chris@16 44
Chris@16 45 template<typename T, typename Policy>
Chris@16 46 inline T acosh_imp(const T x, const Policy& pol)
Chris@16 47 {
Chris@16 48 BOOST_MATH_STD_USING
Chris@16 49
Chris@16 50 if(x < 1)
Chris@16 51 {
Chris@16 52 return policies::raise_domain_error<T>(
Chris@16 53 "boost::math::acosh<%1%>(%1%)",
Chris@16 54 "acosh requires x >= 1, but got x = %1%.", x, pol);
Chris@16 55 }
Chris@16 56 else if ((x - 1) >= tools::root_epsilon<T>())
Chris@16 57 {
Chris@16 58 if (x > 1 / tools::root_epsilon<T>())
Chris@16 59 {
Chris@16 60 // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/06/01/0001/
Chris@16 61 // approximation by laurent series in 1/x at 0+ order from -1 to 0
Chris@16 62 return log(x) + constants::ln_two<T>();
Chris@16 63 }
Chris@16 64 else if(x < 1.5f)
Chris@16 65 {
Chris@16 66 // This is just a rearrangement of the standard form below
Chris@16 67 // devised to minimse loss of precision when x ~ 1:
Chris@16 68 T y = x - 1;
Chris@16 69 return boost::math::log1p(y + sqrt(y * y + 2 * y), pol);
Chris@16 70 }
Chris@16 71 else
Chris@16 72 {
Chris@16 73 // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/
Chris@16 74 return( log( x + sqrt(x * x - 1) ) );
Chris@16 75 }
Chris@16 76 }
Chris@16 77 else
Chris@16 78 {
Chris@16 79 // see http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/04/01/0001/
Chris@16 80 T y = x - 1;
Chris@16 81
Chris@16 82 // approximation by taylor series in y at 0 up to order 2
Chris@16 83 T result = sqrt(2 * y) * (1 - y /12 + 3 * y * y / 160);
Chris@16 84 return result;
Chris@16 85 }
Chris@16 86 }
Chris@16 87 }
Chris@16 88
Chris@16 89 template<typename T, typename Policy>
Chris@16 90 inline typename tools::promote_args<T>::type acosh(T x, const Policy&)
Chris@16 91 {
Chris@16 92 typedef typename tools::promote_args<T>::type result_type;
Chris@16 93 typedef typename policies::evaluation<result_type, Policy>::type value_type;
Chris@16 94 typedef typename policies::normalise<
Chris@16 95 Policy,
Chris@16 96 policies::promote_float<false>,
Chris@16 97 policies::promote_double<false>,
Chris@16 98 policies::discrete_quantile<>,
Chris@16 99 policies::assert_undefined<> >::type forwarding_policy;
Chris@16 100 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
Chris@16 101 detail::acosh_imp(static_cast<value_type>(x), forwarding_policy()),
Chris@16 102 "boost::math::acosh<%1%>(%1%)");
Chris@16 103 }
Chris@16 104 template<typename T>
Chris@16 105 inline typename tools::promote_args<T>::type acosh(T x)
Chris@16 106 {
Chris@16 107 return boost::math::acosh(x, policies::policy<>());
Chris@16 108 }
Chris@16 109
Chris@16 110 }
Chris@16 111 }
Chris@16 112
Chris@16 113 #endif /* BOOST_ACOSH_HPP */
Chris@16 114
Chris@16 115