]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/include/boost/math/special_functions/sin_pi.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / include / boost / math / special_functions / sin_pi.hpp
CommitLineData
7c673cae
FG
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/math_fwd.hpp>
16#include <boost/math/special_functions/trunc.hpp>
17#include <boost/math/tools/promotion.hpp>
18#include <boost/math/constants/constants.hpp>
19
20namespace boost{ namespace math{ namespace detail{
21
22template <class T, class Policy>
23T sin_pi_imp(T x, const Policy& pol)
24{
25 BOOST_MATH_STD_USING // ADL of std names
26 if(x < 0)
27 return -sin_pi(-x);
28 // sin of pi*x:
29 bool invert;
30 if(x < 0.5)
31 return sin(constants::pi<T>() * x);
32 if(x < 1)
33 {
34 invert = true;
35 x = -x;
36 }
37 else
38 invert = false;
39
40 T rem = floor(x);
41 if(itrunc(rem, pol) & 1)
42 invert = !invert;
43 rem = x - rem;
44 if(rem > 0.5f)
45 rem = 1 - rem;
46 if(rem == 0.5f)
47 return static_cast<T>(invert ? -1 : 1);
48
49 rem = sin(constants::pi<T>() * rem);
50 return invert ? T(-rem) : rem;
51}
52
53} // namespace detail
54
55template <class T, class Policy>
56inline typename tools::promote_args<T>::type sin_pi(T x, const Policy&)
57{
58 typedef typename tools::promote_args<T>::type result_type;
59 typedef typename policies::evaluation<result_type, Policy>::type value_type;
60 typedef typename policies::normalise<
61 Policy,
62 policies::promote_float<false>,
63 policies::promote_double<false>,
64 policies::discrete_quantile<>,
65 policies::assert_undefined<> >::type forwarding_policy;
66 return policies::checked_narrowing_cast<result_type, forwarding_policy>(boost::math::detail::sin_pi_imp<value_type>(x, forwarding_policy()), "cos_pi");
67}
68
69template <class T>
70inline typename tools::promote_args<T>::type sin_pi(T x)
71{
72 return boost::math::sin_pi(x, policies::policy<>());
73}
74
75} // namespace math
76} // namespace boost
77#endif
78