Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:36:01

0001 //    boost asinh.hpp header file
0002 
0003 //  (C) Copyright Eric Ford & Hubert Holin 2001.
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_ASINH_HPP
0012 #define BOOST_ASINH_HPP
0013 
0014 #ifdef _MSC_VER
0015 #pragma once
0016 #endif
0017 
0018 
0019 #include <cmath>
0020 #include <boost/math/tools/precision.hpp>
0021 #include <boost/math/special_functions/math_fwd.hpp>
0022 #include <boost/math/special_functions/sqrt1pm1.hpp>
0023 #include <boost/math/special_functions/log1p.hpp>
0024 #include <boost/math/constants/constants.hpp>
0025 #include <boost/math/special_functions/fpclassify.hpp>
0026 
0027 // This is the inverse of the hyperbolic sine function.
0028 
0029 namespace boost
0030 {
0031     namespace math
0032     {
0033        namespace detail{
0034         template<typename T, class Policy>
0035         inline T    asinh_imp(const T x, const Policy& pol)
0036         {
0037             BOOST_MATH_STD_USING
0038             
0039             if((boost::math::isnan)(x))
0040             {
0041                return policies::raise_domain_error<T>("boost::math::asinh<%1%>(%1%)", "asinh requires a finite argument, but got x = %1%.", x, pol);
0042             }
0043             if        (x >= tools::forth_root_epsilon<T>())
0044             {
0045                if        (x > 1 / tools::root_epsilon<T>())
0046                 {
0047                     // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/06/01/0001/
0048                     // approximation by laurent series in 1/x at 0+ order from -1 to 1
0049                     return constants::ln_two<T>() + log(x) + 1/ (4 * x * x);
0050                 }
0051                 else if(x < 0.5f)
0052                 {
0053                    // As below, but rearranged to preserve digits:
0054                    return boost::math::log1p(x + boost::math::sqrt1pm1(x * x, pol), pol);
0055                 }
0056                 else
0057                 {
0058                     // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/
0059                     return( log( x + sqrt(x*x+1) ) );
0060                 }
0061             }
0062             else if    (x <= -tools::forth_root_epsilon<T>())
0063             {
0064                 return(-asinh(-x, pol));
0065             }
0066             else
0067             {
0068                 // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/03/01/0001/
0069                 // approximation by taylor series in x at 0 up to order 2
0070                 T    result = x;
0071                 
0072                 if    (abs(x) >= tools::root_epsilon<T>())
0073                 {
0074                     T    x3 = x*x*x;
0075                     
0076                     // approximation by taylor series in x at 0 up to order 4
0077                     result -= x3/static_cast<T>(6);
0078                 }
0079                 
0080                 return(result);
0081             }
0082         }
0083        }
0084 
0085         template<typename T>
0086         inline typename tools::promote_args<T>::type asinh(T x)
0087         {
0088            return boost::math::asinh(x, policies::policy<>());
0089         }
0090         template<typename T, typename Policy>
0091         inline typename tools::promote_args<T>::type asinh(T x, const Policy&)
0092         {
0093             typedef typename tools::promote_args<T>::type result_type;
0094             typedef typename policies::evaluation<result_type, Policy>::type value_type;
0095             typedef typename policies::normalise<
0096                Policy, 
0097                policies::promote_float<false>, 
0098                policies::promote_double<false>, 
0099                policies::discrete_quantile<>,
0100                policies::assert_undefined<> >::type forwarding_policy;
0101            return policies::checked_narrowing_cast<result_type, forwarding_policy>(
0102               detail::asinh_imp(static_cast<value_type>(x), forwarding_policy()),
0103               "boost::math::asinh<%1%>(%1%)");
0104         }
0105 
0106     }
0107 }
0108 
0109 #endif /* BOOST_ASINH_HPP */
0110