Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:08

0001 //    boost asinh.hpp header file
0002 
0003 //  (C) Copyright Eric Ford 2001 & Hubert Holin.
0004 //  (C) Copyright John Maddock 2008.
0005 //  Distributed under the Boost Software License, Version 1.0. (See
0006 //  accompanying file LICENSE_1_0.txt or copy at
0007 //  http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 // See http://www.boost.org for updates, documentation, and revision history.
0010 
0011 #ifndef BOOST_ACOSH_HPP
0012 #define BOOST_ACOSH_HPP
0013 
0014 #ifdef _MSC_VER
0015 #pragma once
0016 #endif
0017 
0018 #include <cmath>
0019 #include <boost/math/tools/precision.hpp>
0020 #include <boost/math/policies/error_handling.hpp>
0021 #include <boost/math/special_functions/math_fwd.hpp>
0022 #include <boost/math/special_functions/log1p.hpp>
0023 #include <boost/math/constants/constants.hpp>
0024 #include <boost/math/special_functions/fpclassify.hpp>
0025 
0026 // This is the inverse of the hyperbolic cosine function.
0027 
0028 namespace boost
0029 {
0030     namespace math
0031     {
0032        namespace detail
0033        {
0034         template<typename T, typename Policy>
0035         inline T    acosh_imp(const T x, const Policy& pol)
0036         {
0037             BOOST_MATH_STD_USING
0038             
0039             if((x < 1) || (boost::math::isnan)(x))
0040             {
0041                return policies::raise_domain_error<T>(
0042                   "boost::math::acosh<%1%>(%1%)",
0043                   "acosh requires x >= 1, but got x = %1%.", x, pol);
0044             }
0045             else if    ((x - 1) >= tools::root_epsilon<T>())
0046             {
0047                 if    (x > 1 / tools::root_epsilon<T>())
0048                 {
0049                     // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/06/01/0001/
0050                     // approximation by laurent series in 1/x at 0+ order from -1 to 0
0051                     return log(x) + constants::ln_two<T>();
0052                 }
0053                 else if(x < 1.5f)
0054                 {
0055                    // This is just a rearrangement of the standard form below
0056                    // devised to minimise loss of precision when x ~ 1:
0057                    T y = x - 1;
0058                    return boost::math::log1p(y + sqrt(y * y + 2 * y), pol);
0059                 }
0060                 else
0061                 {
0062                     // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/
0063                     return( log( x + sqrt(x * x - 1) ) );
0064                 }
0065             }
0066             else
0067             {
0068                 // see http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/04/01/0001/
0069                 T y = x - 1;
0070                 
0071                 // approximation by taylor series in y at 0 up to order 2
0072                 T result = sqrt(2 * y) * (1 - y /12 + 3 * y * y / 160);
0073                 return result;
0074             }
0075         }
0076        }
0077 
0078         template<typename T, typename Policy>
0079         inline typename tools::promote_args<T>::type acosh(T x, const Policy&)
0080         {
0081             typedef typename tools::promote_args<T>::type result_type;
0082             typedef typename policies::evaluation<result_type, Policy>::type value_type;
0083             typedef typename policies::normalise<
0084                Policy, 
0085                policies::promote_float<false>, 
0086                policies::promote_double<false>, 
0087                policies::discrete_quantile<>,
0088                policies::assert_undefined<> >::type forwarding_policy;
0089            return policies::checked_narrowing_cast<result_type, forwarding_policy>(
0090               detail::acosh_imp(static_cast<value_type>(x), forwarding_policy()),
0091               "boost::math::acosh<%1%>(%1%)");
0092         }
0093         template<typename T>
0094         inline typename tools::promote_args<T>::type acosh(T x)
0095         {
0096            return boost::math::acosh(x, policies::policy<>());
0097         }
0098 
0099     }
0100 }
0101 
0102 #endif /* BOOST_ACOSH_HPP */
0103 
0104