// Copyright (c) 2007 John Maddock // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_MATH_COS_PI_HPP #define BOOST_MATH_COS_PI_HPP #ifdef _MSC_VER #pragma once #endif #include #include #include #include #include #include namespace boost{ namespace math{ namespace detail{ template T cos_pi_imp(T x, const Policy& pol) { BOOST_MATH_STD_USING // ADL of std names // cos of pi*x: bool invert = false; if(fabs(x) < 0.25) return cos(constants::pi() * x); if(x < 0) { x = -x; } T rem = floor(x); if(iconvert(rem, pol) & 1) invert = !invert; rem = x - rem; if(rem > 0.5f) { rem = 1 - rem; invert = !invert; } if(rem == 0.5f) return 0; if(rem > 0.25f) { rem = 0.5f - rem; rem = sin(constants::pi() * rem); } else rem = cos(constants::pi() * rem); return invert ? T(-rem) : rem; } } // namespace detail template inline typename tools::promote_args::type cos_pi(T x, const Policy&) { typedef typename tools::promote_args::type result_type; typedef typename policies::evaluation::type value_type; typedef typename policies::normalise< Policy, policies::promote_float, policies::promote_double, policies::discrete_quantile<>, policies::assert_undefined<>, // We want to ignore overflows since the result is in [-1,1] and the // check slows the code down considerably. policies::overflow_error >::type forwarding_policy; return policies::checked_narrowing_cast(boost::math::detail::cos_pi_imp(x, forwarding_policy()), "cos_pi"); } template inline typename tools::promote_args::type cos_pi(T x) { return boost::math::cos_pi(x, policies::policy<>()); } } // namespace math } // namespace boost #endif