]> git.donarmstrong.com Git - rsem.git/blob - boost/math/special_functions/powm1.hpp
RSEM Source Codes
[rsem.git] / boost / math / special_functions / powm1.hpp
1 //  (C) Copyright John Maddock 2006.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef BOOST_MATH_POWM1
7 #define BOOST_MATH_POWM1
8
9 #ifdef _MSC_VER
10 #pragma once
11 #endif
12
13 #include <boost/math/special_functions/log1p.hpp>
14 #include <boost/math/special_functions/expm1.hpp>
15 #include <boost/math/special_functions/math_fwd.hpp>
16 #include <boost/assert.hpp>
17
18 namespace boost{ namespace math{ namespace detail{
19
20 template <class T, class Policy>
21 inline T powm1_imp(const T a, const T z, const Policy& pol)
22 {
23    BOOST_MATH_STD_USING
24
25    if((fabs(a) < 1) || (fabs(z) < 1))
26    {
27       T p = log(a) * z;
28       if(fabs(p) < 2)
29          return boost::math::expm1(p, pol);
30       // otherwise fall though:
31    }
32    return pow(a, z) - 1;
33 }
34
35 } // detail
36
37 template <class T1, class T2>
38 inline typename tools::promote_args<T1, T2>::type 
39    powm1(const T1 a, const T2 z)
40 {
41    typedef typename tools::promote_args<T1, T2>::type result_type;
42    return detail::powm1_imp(static_cast<result_type>(a), static_cast<result_type>(z), policies::policy<>());
43 }
44
45 template <class T1, class T2, class Policy>
46 inline typename tools::promote_args<T1, T2>::type 
47    powm1(const T1 a, const T2 z, const Policy& pol)
48 {
49    typedef typename tools::promote_args<T1, T2>::type result_type;
50    return detail::powm1_imp(static_cast<result_type>(a), static_cast<result_type>(z), pol);
51 }
52
53 } // namespace math
54 } // namespace boost
55
56 #endif // BOOST_MATH_POWM1
57
58
59
60
61