]> git.donarmstrong.com Git - rsem.git/blob - boost/math/special_functions/asinh.hpp
Added error detection for cases such as a read's two mates having different names...
[rsem.git] / boost / math / special_functions / asinh.hpp
1 //    boost asinh.hpp header file
2
3 //  (C) Copyright Eric Ford & Hubert Holin 2001.
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_ASINH_HPP
12 #define BOOST_ASINH_HPP
13
14 #ifdef _MSC_VER
15 #pragma once
16 #endif
17
18
19 #include <boost/config/no_tr1/cmath.hpp>
20 #include <boost/config.hpp>
21 #include <boost/math/tools/precision.hpp>
22 #include <boost/math/special_functions/math_fwd.hpp>
23 #include <boost/math/special_functions/sqrt1pm1.hpp>
24 #include <boost/math/special_functions/log1p.hpp>
25 #include <boost/math/constants/constants.hpp>
26
27 // This is the inverse of the hyperbolic sine function.
28
29 namespace boost
30 {
31     namespace math
32     {
33        namespace detail{
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, class Policy>
46         inline T    asinh_imp(const T x, const Policy& pol)
47         {
48             BOOST_MATH_STD_USING
49             
50             if        (x >= tools::forth_root_epsilon<T>())
51             {
52                if        (x > 1 / tools::root_epsilon<T>())
53                 {
54                     // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/06/01/0001/
55                     // approximation by laurent series in 1/x at 0+ order from -1 to 1
56                     return constants::ln_two<T>() + log(x) + 1/ (4 * x * x);
57                 }
58                 else if(x < 0.5f)
59                 {
60                    // As below, but rearranged to preserve digits:
61                    return boost::math::log1p(x + boost::math::sqrt1pm1(x * x, pol), pol);
62                 }
63                 else
64                 {
65                     // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/
66                     return( log( x + sqrt(x*x+1) ) );
67                 }
68             }
69             else if    (x <= -tools::forth_root_epsilon<T>())
70             {
71                 return(-asinh(-x, pol));
72             }
73             else
74             {
75                 // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/03/01/0001/
76                 // approximation by taylor series in x at 0 up to order 2
77                 T    result = x;
78                 
79                 if    (abs(x) >= tools::root_epsilon<T>())
80                 {
81                     T    x3 = x*x*x;
82                     
83                     // approximation by taylor series in x at 0 up to order 4
84                     result -= x3/static_cast<T>(6);
85                 }
86                 
87                 return(result);
88             }
89         }
90        }
91
92         template<typename T>
93         inline typename tools::promote_args<T>::type asinh(T x)
94         {
95            return boost::math::asinh(x, policies::policy<>());
96         }
97         template<typename T, typename Policy>
98         inline typename tools::promote_args<T>::type asinh(T x, const Policy&)
99         {
100             typedef typename tools::promote_args<T>::type result_type;
101             typedef typename policies::evaluation<result_type, Policy>::type value_type;
102             typedef typename policies::normalise<
103                Policy, 
104                policies::promote_float<false>, 
105                policies::promote_double<false>, 
106                policies::discrete_quantile<>,
107                policies::assert_undefined<> >::type forwarding_policy;
108            return policies::checked_narrowing_cast<result_type, forwarding_policy>(
109               detail::asinh_imp(static_cast<value_type>(x), forwarding_policy()),
110               "boost::math::asinh<%1%>(%1%)");
111         }
112
113     }
114 }
115
116 #endif /* BOOST_ASINH_HPP */
117