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.hpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/boost/math/special_functions/cos_pi.hpp b/boost/math/special_functions/cos_pi.hpp
new file mode 100644
index 0000000000..93102c1cb3
--- /dev/null
+++ b/boost/math/special_functions/cos_pi.hpp
@@ -0,0 +1,68 @@
+// 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 <boost/config/no_tr1/cmath.hpp>
+#include <boost/math/tools/config.hpp>
+#include <boost/math/special_functions/trunc.hpp>
+#include <boost/math/tools/promotion.hpp>
+#include <boost/math/constants/constants.hpp>
+
+namespace boost{ namespace math{ namespace detail{
+
+template <class T, class Policy>
+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)
+ return cos(constants::pi<T>() * x);
+
+ if(x < 1)
+ {
+ x = -x;
+ }
+ T rem = floor(x);
+ if(itrunc(rem, pol) & 1)
+ invert = !invert;
+ rem = x - rem;
+ if(rem > 0.5f)
+ {
+ rem = 1 - rem;
+ invert = !invert;
+ }
+ if(rem == 0.5f)
+ return 0;
+
+ 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)
+{
+ typedef typename tools::promote_args<T>::type result_type;
+ return boost::math::detail::cos_pi_imp<result_type>(x, pol);
+}
+
+template <class T>
+inline typename tools::promote_args<T>::type cos_pi(T x)
+{
+ return boost::math::cos_pi(x, policies::policy<>());
+}
+
+} // namespace math
+} // namespace boost
+#endif
+