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)
6 #ifndef BOOST_MATH_COS_PI_HPP
7 #define BOOST_MATH_COS_PI_HPP
15 #include <boost/math/special_functions/math_fwd.hpp>
16 #include <boost/math/tools/config.hpp>
17 #include <boost/math/special_functions/trunc.hpp>
18 #include <boost/math/tools/promotion.hpp>
19 #include <boost/math/constants/constants.hpp>
21 namespace boost{ namespace math{ namespace detail{
23 template <class T, class Policy>
24 T cos_pi_imp(T x, const Policy&)
26 BOOST_MATH_STD_USING // ADL of std names
30 return cos(constants::pi<T>() * x);
37 if(abs(floor(rem/2)*2 - rem) > std::numeric_limits<T>::epsilon())
53 rem = sin(constants::pi<T>() * rem);
56 rem = cos(constants::pi<T>() * rem);
57 return invert ? T(-rem) : rem;
62 template <class T, class Policy>
63 inline typename tools::promote_args<T>::type cos_pi(T x, const Policy&)
65 typedef typename tools::promote_args<T>::type result_type;
66 typedef typename policies::evaluation<result_type, Policy>::type value_type;
67 typedef typename policies::normalise<
69 policies::promote_float<false>,
70 policies::promote_double<false>,
71 policies::discrete_quantile<>,
72 policies::assert_undefined<>,
73 // We want to ignore overflows since the result is in [-1,1] and the
74 // check slows the code down considerably.
75 policies::overflow_error<policies::ignore_error> >::type forwarding_policy;
76 return policies::checked_narrowing_cast<result_type, forwarding_policy>(boost::math::detail::cos_pi_imp<value_type>(x, forwarding_policy()), "cos_pi");
80 inline typename tools::promote_args<T>::type cos_pi(T x)
82 return boost::math::cos_pi(x, policies::policy<>());