]> git.donarmstrong.com Git - rsem.git/blob - boost/math/special_functions/cos_pi.hpp
Updated boost to v1.55.0
[rsem.git] / boost / math / special_functions / cos_pi.hpp
1 //  Copyright (c) 2007 John Maddock
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_COS_PI_HPP
7 #define BOOST_MATH_COS_PI_HPP
8
9 #ifdef _MSC_VER
10 #pragma once
11 #endif
12
13 #include <boost/config/no_tr1/cmath.hpp>
14 #include <boost/math/tools/config.hpp>
15 #include <boost/math/special_functions/trunc.hpp>
16 #include <boost/math/tools/promotion.hpp>
17 #include <boost/math/constants/constants.hpp>
18
19 namespace boost{ namespace math{ namespace detail{
20
21 template <class T, class Policy>
22 T cos_pi_imp(T x, const Policy& pol)
23 {
24    BOOST_MATH_STD_USING // ADL of std names
25    // cos of pi*x:
26    bool invert = false;
27    if(fabs(x) < 0.5)
28       return cos(constants::pi<T>() * x);
29
30    if(x < 1)
31    {
32       x = -x;
33    }
34    T rem = floor(x);
35    if(itrunc(rem, pol) & 1)
36       invert = !invert;
37    rem = x - rem;
38    if(rem > 0.5f)
39    {
40       rem = 1 - rem;
41       invert = !invert;
42    }
43    if(rem == 0.5f)
44       return 0;
45    
46    rem = cos(constants::pi<T>() * rem);
47    return invert ? T(-rem) : rem;
48 }
49
50 } // namespace detail
51
52 template <class T, class Policy>
53 inline typename tools::promote_args<T>::type cos_pi(T x, const Policy& pol)
54 {
55    typedef typename tools::promote_args<T>::type result_type;
56    return boost::math::detail::cos_pi_imp<result_type>(x, pol);
57 }
58
59 template <class T>
60 inline typename tools::promote_args<T>::type cos_pi(T x)
61 {
62    return boost::math::cos_pi(x, policies::policy<>());
63 }
64
65 } // namespace math
66 } // namespace boost
67 #endif
68