annotate DEPENDENCIES/generic/include/boost/math/special_functions/atanh.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // boost atanh.hpp header file
Chris@16 2
Chris@16 3 // (C) Copyright Hubert Holin 2001.
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_ATANH_HPP
Chris@16 12 #define BOOST_ATANH_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
Chris@16 19 #include <boost/config/no_tr1/cmath.hpp>
Chris@16 20 #include <boost/config.hpp>
Chris@16 21 #include <boost/math/tools/precision.hpp>
Chris@16 22 #include <boost/math/policies/error_handling.hpp>
Chris@16 23 #include <boost/math/special_functions/math_fwd.hpp>
Chris@16 24 #include <boost/math/special_functions/log1p.hpp>
Chris@16 25
Chris@16 26 // This is the inverse of the hyperbolic tangent 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 // This is the main fare
Chris@16 35
Chris@16 36 template<typename T, typename Policy>
Chris@16 37 inline T atanh_imp(const T x, const Policy& pol)
Chris@16 38 {
Chris@16 39 BOOST_MATH_STD_USING
Chris@16 40 static const char* function = "boost::math::atanh<%1%>(%1%)";
Chris@16 41
Chris@16 42 if(x < -1)
Chris@16 43 {
Chris@16 44 return policies::raise_domain_error<T>(
Chris@16 45 function,
Chris@16 46 "atanh requires x >= -1, but got x = %1%.", x, pol);
Chris@16 47 }
Chris@16 48 else if(x > 1)
Chris@16 49 {
Chris@16 50 return policies::raise_domain_error<T>(
Chris@16 51 function,
Chris@16 52 "atanh requires x <= 1, but got x = %1%.", x, pol);
Chris@16 53 }
Chris@16 54 else if(x < -1 + tools::epsilon<T>())
Chris@16 55 {
Chris@16 56 // -Infinity:
Chris@16 57 return -policies::raise_overflow_error<T>(function, 0, pol);
Chris@16 58 }
Chris@16 59 else if(x > 1 - tools::epsilon<T>())
Chris@16 60 {
Chris@16 61 // Infinity:
Chris@16 62 return policies::raise_overflow_error<T>(function, 0, pol);
Chris@16 63 }
Chris@16 64 else if(abs(x) >= tools::forth_root_epsilon<T>())
Chris@16 65 {
Chris@16 66 // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/
Chris@16 67 if(abs(x) < 0.5f)
Chris@16 68 return (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2;
Chris@16 69 return(log( (1 + x) / (1 - x) ) / 2);
Chris@16 70 }
Chris@16 71 else
Chris@16 72 {
Chris@16 73 // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/06/01/03/01/
Chris@16 74 // approximation by taylor series in x at 0 up to order 2
Chris@16 75 T result = x;
Chris@16 76
Chris@16 77 if (abs(x) >= tools::root_epsilon<T>())
Chris@16 78 {
Chris@16 79 T x3 = x*x*x;
Chris@16 80
Chris@16 81 // approximation by taylor series in x at 0 up to order 4
Chris@16 82 result += x3/static_cast<T>(3);
Chris@16 83 }
Chris@16 84
Chris@16 85 return(result);
Chris@16 86 }
Chris@16 87 }
Chris@16 88 }
Chris@16 89
Chris@16 90 template<typename T, typename Policy>
Chris@16 91 inline typename tools::promote_args<T>::type atanh(T x, const Policy&)
Chris@16 92 {
Chris@16 93 typedef typename tools::promote_args<T>::type result_type;
Chris@16 94 typedef typename policies::evaluation<result_type, Policy>::type value_type;
Chris@16 95 typedef typename policies::normalise<
Chris@16 96 Policy,
Chris@16 97 policies::promote_float<false>,
Chris@16 98 policies::promote_double<false>,
Chris@16 99 policies::discrete_quantile<>,
Chris@16 100 policies::assert_undefined<> >::type forwarding_policy;
Chris@16 101 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
Chris@16 102 detail::atanh_imp(static_cast<value_type>(x), forwarding_policy()),
Chris@16 103 "boost::math::atanh<%1%>(%1%)");
Chris@16 104 }
Chris@16 105 template<typename T>
Chris@16 106 inline typename tools::promote_args<T>::type atanh(T x)
Chris@16 107 {
Chris@16 108 return boost::math::atanh(x, policies::policy<>());
Chris@16 109 }
Chris@16 110
Chris@16 111 }
Chris@16 112 }
Chris@16 113
Chris@16 114 #endif /* BOOST_ATANH_HPP */
Chris@16 115
Chris@16 116
Chris@16 117