annotate DEPENDENCIES/generic/include/boost/math/special_functions/cos_pi.hpp @ 47:fe753ff3d0b5

Simpler solution to .cat test
author Chris Cannam
date Thu, 07 Aug 2014 15:05:37 +0100
parents 2665513ce2d3
children c530137014c0
rev   line source
Chris@16 1 // Copyright (c) 2007 John Maddock
Chris@16 2 // Use, modification and distribution are subject to the
Chris@16 3 // Boost Software License, Version 1.0. (See accompanying file
Chris@16 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5
Chris@16 6 #ifndef BOOST_MATH_COS_PI_HPP
Chris@16 7 #define BOOST_MATH_COS_PI_HPP
Chris@16 8
Chris@16 9 #ifdef _MSC_VER
Chris@16 10 #pragma once
Chris@16 11 #endif
Chris@16 12
Chris@16 13 #include <boost/config/no_tr1/cmath.hpp>
Chris@16 14 #include <boost/math/tools/config.hpp>
Chris@16 15 #include <boost/math/special_functions/trunc.hpp>
Chris@16 16 #include <boost/math/tools/promotion.hpp>
Chris@16 17 #include <boost/math/constants/constants.hpp>
Chris@16 18
Chris@16 19 namespace boost{ namespace math{ namespace detail{
Chris@16 20
Chris@16 21 template <class T, class Policy>
Chris@16 22 T cos_pi_imp(T x, const Policy& pol)
Chris@16 23 {
Chris@16 24 BOOST_MATH_STD_USING // ADL of std names
Chris@16 25 // cos of pi*x:
Chris@16 26 bool invert = false;
Chris@16 27 if(fabs(x) < 0.5)
Chris@16 28 return cos(constants::pi<T>() * x);
Chris@16 29
Chris@16 30 if(x < 1)
Chris@16 31 {
Chris@16 32 x = -x;
Chris@16 33 }
Chris@16 34 T rem = floor(x);
Chris@16 35 if(itrunc(rem, pol) & 1)
Chris@16 36 invert = !invert;
Chris@16 37 rem = x - rem;
Chris@16 38 if(rem > 0.5f)
Chris@16 39 {
Chris@16 40 rem = 1 - rem;
Chris@16 41 invert = !invert;
Chris@16 42 }
Chris@16 43 if(rem == 0.5f)
Chris@16 44 return 0;
Chris@16 45
Chris@16 46 rem = cos(constants::pi<T>() * rem);
Chris@16 47 return invert ? T(-rem) : rem;
Chris@16 48 }
Chris@16 49
Chris@16 50 } // namespace detail
Chris@16 51
Chris@16 52 template <class T, class Policy>
Chris@16 53 inline typename tools::promote_args<T>::type cos_pi(T x, const Policy& pol)
Chris@16 54 {
Chris@16 55 typedef typename tools::promote_args<T>::type result_type;
Chris@16 56 return boost::math::detail::cos_pi_imp<result_type>(x, pol);
Chris@16 57 }
Chris@16 58
Chris@16 59 template <class T>
Chris@16 60 inline typename tools::promote_args<T>::type cos_pi(T x)
Chris@16 61 {
Chris@16 62 return boost::math::cos_pi(x, policies::policy<>());
Chris@16 63 }
Chris@16 64
Chris@16 65 } // namespace math
Chris@16 66 } // namespace boost
Chris@16 67 #endif
Chris@16 68