summaryrefslogtreecommitdiff log msg author committer range
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 ``` ``````// boost atanh.hpp header file // (C) Copyright 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_ATANH_HPP #define BOOST_ATANH_HPP #ifdef _MSC_VER #pragma once #endif #include #include #include #include #include #include // This is the inverse of the hyperbolic tangent function. namespace boost { namespace math { namespace detail { // This is the main fare template inline T atanh_imp(const T x, const Policy& pol) { BOOST_MATH_STD_USING static const char* function = "boost::math::atanh<%1%>(%1%)"; if(x < -1) { return policies::raise_domain_error( function, "atanh requires x >= -1, but got x = %1%.", x, pol); } else if(x > 1) { return policies::raise_domain_error( function, "atanh requires x <= 1, but got x = %1%.", x, pol); } else if(x < -1 + tools::epsilon()) { // -Infinity: return -policies::raise_overflow_error(function, 0, pol); } else if(x > 1 - tools::epsilon()) { // Infinity: return policies::raise_overflow_error(function, 0, pol); } else if(abs(x) >= tools::forth_root_epsilon()) { // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/ if(abs(x) < 0.5f) return (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2; return(log( (1 + x) / (1 - x) ) / 2); } else { // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/06/01/03/01/ // 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(3); } return(result); } } } template inline typename tools::promote_args::type atanh(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::atanh_imp(static_cast(x), forwarding_policy()), "boost::math::atanh<%1%>(%1%)"); } template inline typename tools::promote_args::type atanh(T x) { return boost::math::atanh(x, policies::policy<>()); } } } #endif /* BOOST_ATANH_HPP */ ``````