annotate DEPENDENCIES/generic/include/boost/math/special_functions/atanh.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
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 #if defined(__GNUC__) && (__GNUC__ < 3)
Chris@16 35 // gcc 2.x ignores function scope using declarations,
Chris@16 36 // put them in the scope of the enclosing namespace instead:
Chris@16 37
Chris@16 38 using ::std::abs;
Chris@16 39 using ::std::sqrt;
Chris@16 40 using ::std::log;
Chris@16 41
Chris@16 42 using ::std::numeric_limits;
Chris@16 43 #endif
Chris@16 44
Chris@16 45 // This is the main fare
Chris@16 46
Chris@16 47 template<typename T, typename Policy>
Chris@16 48 inline T atanh_imp(const T x, const Policy& pol)
Chris@16 49 {
Chris@16 50 BOOST_MATH_STD_USING
Chris@16 51 static const char* function = "boost::math::atanh<%1%>(%1%)";
Chris@16 52
Chris@16 53 if(x < -1)
Chris@16 54 {
Chris@16 55 return policies::raise_domain_error<T>(
Chris@16 56 function,
Chris@16 57 "atanh requires x >= -1, but got x = %1%.", x, pol);
Chris@16 58 }
Chris@16 59 else if(x > 1)
Chris@16 60 {
Chris@16 61 return policies::raise_domain_error<T>(
Chris@16 62 function,
Chris@16 63 "atanh requires x <= 1, but got x = %1%.", x, pol);
Chris@16 64 }
Chris@16 65 else if(x < -1 + tools::epsilon<T>())
Chris@16 66 {
Chris@16 67 // -Infinity:
Chris@16 68 return -policies::raise_overflow_error<T>(function, 0, pol);
Chris@16 69 }
Chris@16 70 else if(x > 1 - tools::epsilon<T>())
Chris@16 71 {
Chris@16 72 // Infinity:
Chris@16 73 return policies::raise_overflow_error<T>(function, 0, pol);
Chris@16 74 }
Chris@16 75 else if(abs(x) >= tools::forth_root_epsilon<T>())
Chris@16 76 {
Chris@16 77 // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/
Chris@16 78 if(abs(x) < 0.5f)
Chris@16 79 return (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2;
Chris@16 80 return(log( (1 + x) / (1 - x) ) / 2);
Chris@16 81 }
Chris@16 82 else
Chris@16 83 {
Chris@16 84 // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/06/01/03/01/
Chris@16 85 // approximation by taylor series in x at 0 up to order 2
Chris@16 86 T result = x;
Chris@16 87
Chris@16 88 if (abs(x) >= tools::root_epsilon<T>())
Chris@16 89 {
Chris@16 90 T x3 = x*x*x;
Chris@16 91
Chris@16 92 // approximation by taylor series in x at 0 up to order 4
Chris@16 93 result += x3/static_cast<T>(3);
Chris@16 94 }
Chris@16 95
Chris@16 96 return(result);
Chris@16 97 }
Chris@16 98 }
Chris@16 99 }
Chris@16 100
Chris@16 101 template<typename T, typename Policy>
Chris@16 102 inline typename tools::promote_args<T>::type atanh(T x, const Policy&)
Chris@16 103 {
Chris@16 104 typedef typename tools::promote_args<T>::type result_type;
Chris@16 105 typedef typename policies::evaluation<result_type, Policy>::type value_type;
Chris@16 106 typedef typename policies::normalise<
Chris@16 107 Policy,
Chris@16 108 policies::promote_float<false>,
Chris@16 109 policies::promote_double<false>,
Chris@16 110 policies::discrete_quantile<>,
Chris@16 111 policies::assert_undefined<> >::type forwarding_policy;
Chris@16 112 return policies::checked_narrowing_cast<result_type, forwarding_policy>(
Chris@16 113 detail::atanh_imp(static_cast<value_type>(x), forwarding_policy()),
Chris@16 114 "boost::math::atanh<%1%>(%1%)");
Chris@16 115 }
Chris@16 116 template<typename T>
Chris@16 117 inline typename tools::promote_args<T>::type atanh(T x)
Chris@16 118 {
Chris@16 119 return boost::math::atanh(x, policies::policy<>());
Chris@16 120 }
Chris@16 121
Chris@16 122 }
Chris@16 123 }
Chris@16 124
Chris@16 125 #endif /* BOOST_ATANH_HPP */
Chris@16 126
Chris@16 127
Chris@16 128