]> git.donarmstrong.com Git - rsem.git/blob - boost/math/special_functions/sin_pi.hpp
Updated boost to v1.55.0
[rsem.git] / boost / math / special_functions / sin_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_SIN_PI_HPP
7 #define BOOST_MATH_SIN_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 sin_pi_imp(T x, const Policy& pol)
23 {
24    BOOST_MATH_STD_USING // ADL of std names
25    if(x < 0)
26       return -sin_pi(-x);
27    // sin of pi*x:
28    bool invert;
29    if(x < 0.5)
30       return sin(constants::pi<T>() * x);
31    if(x < 1)
32    {
33       invert = true;
34       x = -x;
35    }
36    else
37       invert = false;
38
39    T rem = floor(x);
40    if(itrunc(rem, pol) & 1)
41       invert = !invert;
42    rem = x - rem;
43    if(rem > 0.5f)
44       rem = 1 - rem;
45    if(rem == 0.5f)
46       return static_cast<T>(invert ? -1 : 1);
47    
48    rem = sin(constants::pi<T>() * rem);
49    return invert ? T(-rem) : rem;
50 }
51
52 } // namespace detail
53
54 template <class T, class Policy>
55 inline typename tools::promote_args<T>::type sin_pi(T x, const Policy& pol)
56 {
57    typedef typename tools::promote_args<T>::type result_type;
58    return boost::math::detail::sin_pi_imp<result_type>(x, pol);
59 }
60
61 template <class T>
62 inline typename tools::promote_args<T>::type sin_pi(T x)
63 {
64    return boost::math::sin_pi(x, policies::policy<>());
65 }
66
67 } // namespace math
68 } // namespace boost
69 #endif
70