// boost asinh.hpp header file // (C) Copyright Eric Ford & Hubert Holin 2001. // (C) Copyright John Maddock 2008. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org for updates, documentation, and revision history. #ifndef BOOST_ASINH_HPP #define BOOST_ASINH_HPP #ifdef _MSC_VER #pragma once #endif #include #include #include #include #include #include #include // This is the inverse of the hyperbolic sine function. namespace boost { namespace math { namespace detail{ template inline T asinh_imp(const T x, const Policy& pol) { BOOST_MATH_STD_USING if((boost::math::isnan)(x)) { return policies::raise_domain_error("boost::math::asinh<%1%>(%1%)", "asinh requires a finite argument, but got x = %1%.", x, pol); } if (x >= tools::forth_root_epsilon()) { if (x > 1 / tools::root_epsilon()) { // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/06/01/0001/ // approximation by laurent series in 1/x at 0+ order from -1 to 1 return constants::ln_two() + log(x) + 1/ (4 * x * x); } else if(x < 0.5f) { // As below, but rearranged to preserve digits: return boost::math::log1p(x + boost::math::sqrt1pm1(x * x, pol), pol); } else { // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/ return( log( x + sqrt(x*x+1) ) ); } } else if (x <= -tools::forth_root_epsilon()) { return(-asinh(-x, pol)); } else { // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/03/01/0001/ // approximation by taylor series in x at 0 up to order 2 T result = x; if (abs(x) >= tools::root_epsilon()) { T x3 = x*x*x; // approximation by taylor series in x at 0 up to order 4 result -= x3/static_cast(6); } return(result); } } } template inline typename tools::promote_args::type asinh(T x) { return boost::math::asinh(x, policies::policy<>()); } template inline typename tools::promote_args::type asinh(T x, const Policy&) { typedef typename tools::promote_args::type result_type; typedef typename policies::evaluation::type value_type; typedef typename policies::normalise< Policy, policies::promote_float, policies::promote_double, policies::discrete_quantile<>, policies::assert_undefined<> >::type forwarding_policy; return policies::checked_narrowing_cast( detail::asinh_imp(static_cast(x), forwarding_policy()), "boost::math::asinh<%1%>(%1%)"); } } } #endif /* BOOST_ASINH_HPP */