Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/math/special_functions/acosh.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // boost asinh.hpp header file | |
2 | |
3 // (C) Copyright Eric Ford 2001 & Hubert Holin. | |
4 // (C) Copyright John Maddock 2008. | |
5 // Distributed under the Boost Software License, Version 1.0. (See | |
6 // accompanying file LICENSE_1_0.txt or copy at | |
7 // http://www.boost.org/LICENSE_1_0.txt) | |
8 | |
9 // See http://www.boost.org for updates, documentation, and revision history. | |
10 | |
11 #ifndef BOOST_ACOSH_HPP | |
12 #define BOOST_ACOSH_HPP | |
13 | |
14 #ifdef _MSC_VER | |
15 #pragma once | |
16 #endif | |
17 | |
18 #include <boost/config/no_tr1/cmath.hpp> | |
19 #include <boost/config.hpp> | |
20 #include <boost/math/tools/precision.hpp> | |
21 #include <boost/math/policies/error_handling.hpp> | |
22 #include <boost/math/special_functions/math_fwd.hpp> | |
23 #include <boost/math/special_functions/log1p.hpp> | |
24 #include <boost/math/constants/constants.hpp> | |
25 | |
26 // This is the inverse of the hyperbolic cosine function. | |
27 | |
28 namespace boost | |
29 { | |
30 namespace math | |
31 { | |
32 namespace detail | |
33 { | |
34 #if defined(__GNUC__) && (__GNUC__ < 3) | |
35 // gcc 2.x ignores function scope using declarations, | |
36 // put them in the scope of the enclosing namespace instead: | |
37 | |
38 using ::std::abs; | |
39 using ::std::sqrt; | |
40 using ::std::log; | |
41 | |
42 using ::std::numeric_limits; | |
43 #endif | |
44 | |
45 template<typename T, typename Policy> | |
46 inline T acosh_imp(const T x, const Policy& pol) | |
47 { | |
48 BOOST_MATH_STD_USING | |
49 | |
50 if(x < 1) | |
51 { | |
52 return policies::raise_domain_error<T>( | |
53 "boost::math::acosh<%1%>(%1%)", | |
54 "acosh requires x >= 1, but got x = %1%.", x, pol); | |
55 } | |
56 else if ((x - 1) >= tools::root_epsilon<T>()) | |
57 { | |
58 if (x > 1 / tools::root_epsilon<T>()) | |
59 { | |
60 // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/06/01/0001/ | |
61 // approximation by laurent series in 1/x at 0+ order from -1 to 0 | |
62 return log(x) + constants::ln_two<T>(); | |
63 } | |
64 else if(x < 1.5f) | |
65 { | |
66 // This is just a rearrangement of the standard form below | |
67 // devised to minimse loss of precision when x ~ 1: | |
68 T y = x - 1; | |
69 return boost::math::log1p(y + sqrt(y * y + 2 * y), pol); | |
70 } | |
71 else | |
72 { | |
73 // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/ | |
74 return( log( x + sqrt(x * x - 1) ) ); | |
75 } | |
76 } | |
77 else | |
78 { | |
79 // see http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/04/01/0001/ | |
80 T y = x - 1; | |
81 | |
82 // approximation by taylor series in y at 0 up to order 2 | |
83 T result = sqrt(2 * y) * (1 - y /12 + 3 * y * y / 160); | |
84 return result; | |
85 } | |
86 } | |
87 } | |
88 | |
89 template<typename T, typename Policy> | |
90 inline typename tools::promote_args<T>::type acosh(T x, const Policy&) | |
91 { | |
92 typedef typename tools::promote_args<T>::type result_type; | |
93 typedef typename policies::evaluation<result_type, Policy>::type value_type; | |
94 typedef typename policies::normalise< | |
95 Policy, | |
96 policies::promote_float<false>, | |
97 policies::promote_double<false>, | |
98 policies::discrete_quantile<>, | |
99 policies::assert_undefined<> >::type forwarding_policy; | |
100 return policies::checked_narrowing_cast<result_type, forwarding_policy>( | |
101 detail::acosh_imp(static_cast<value_type>(x), forwarding_policy()), | |
102 "boost::math::acosh<%1%>(%1%)"); | |
103 } | |
104 template<typename T> | |
105 inline typename tools::promote_args<T>::type acosh(T x) | |
106 { | |
107 return boost::math::acosh(x, policies::policy<>()); | |
108 } | |
109 | |
110 } | |
111 } | |
112 | |
113 #endif /* BOOST_ACOSH_HPP */ | |
114 | |
115 |