summaryrefslogtreecommitdiff
path: root/boost/math/special_functions/cos_pi.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/math/special_functions/cos_pi.hpp')
-rw-r--r--boost/math/special_functions/cos_pi.hpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/boost/math/special_functions/cos_pi.hpp b/boost/math/special_functions/cos_pi.hpp
index 18d06c00df..669a2c87ae 100644
--- a/boost/math/special_functions/cos_pi.hpp
+++ b/boost/math/special_functions/cos_pi.hpp
@@ -25,10 +25,10 @@ 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.5)
+ if(fabs(x) < 0.25)
return cos(constants::pi<T>() * x);
- if(x < 1)
+ if(x < 0)
{
x = -x;
}
@@ -44,17 +44,30 @@ T cos_pi_imp(T x, const Policy& pol)
if(rem == 0.5f)
return 0;
- rem = cos(constants::pi<T>() * rem);
+ if(rem > 0.25f)
+ {
+ rem = 0.5f - rem;
+ rem = sin(constants::pi<T>() * rem);
+ }
+ else
+ rem = cos(constants::pi<T>() * rem);
return invert ? T(-rem) : rem;
}
} // namespace detail
template <class T, class Policy>
-inline typename tools::promote_args<T>::type cos_pi(T x, const Policy& pol)
+inline typename tools::promote_args<T>::type cos_pi(T x, const Policy&)
{
typedef typename tools::promote_args<T>::type result_type;
- return boost::math::detail::cos_pi_imp<result_type>(x, pol);
+ typedef typename policies::evaluation<result_type, Policy>::type value_type;
+ typedef typename policies::normalise<
+ Policy,
+ policies::promote_float<false>,
+ policies::promote_double<false>,
+ policies::discrete_quantile<>,
+ policies::assert_undefined<> >::type forwarding_policy;
+ return policies::checked_narrowing_cast<result_type, forwarding_policy>(boost::math::detail::cos_pi_imp<value_type>(x, forwarding_policy()), "cos_pi");
}
template <class T>