annotate DEPENDENCIES/generic/include/boost/math/special_functions/sin_pi.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
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_SIN_PI_HPP
Chris@16 7 #define BOOST_MATH_SIN_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@101 15 #include <boost/math/special_functions/math_fwd.hpp>
Chris@16 16 #include <boost/math/special_functions/trunc.hpp>
Chris@16 17 #include <boost/math/tools/promotion.hpp>
Chris@16 18 #include <boost/math/constants/constants.hpp>
Chris@16 19
Chris@16 20 namespace boost{ namespace math{ namespace detail{
Chris@16 21
Chris@16 22 template <class T, class Policy>
Chris@16 23 T sin_pi_imp(T x, const Policy& pol)
Chris@16 24 {
Chris@16 25 BOOST_MATH_STD_USING // ADL of std names
Chris@16 26 if(x < 0)
Chris@16 27 return -sin_pi(-x);
Chris@16 28 // sin of pi*x:
Chris@16 29 bool invert;
Chris@16 30 if(x < 0.5)
Chris@16 31 return sin(constants::pi<T>() * x);
Chris@16 32 if(x < 1)
Chris@16 33 {
Chris@16 34 invert = true;
Chris@16 35 x = -x;
Chris@16 36 }
Chris@16 37 else
Chris@16 38 invert = false;
Chris@16 39
Chris@16 40 T rem = floor(x);
Chris@16 41 if(itrunc(rem, pol) & 1)
Chris@16 42 invert = !invert;
Chris@16 43 rem = x - rem;
Chris@16 44 if(rem > 0.5f)
Chris@16 45 rem = 1 - rem;
Chris@16 46 if(rem == 0.5f)
Chris@16 47 return static_cast<T>(invert ? -1 : 1);
Chris@16 48
Chris@16 49 rem = sin(constants::pi<T>() * rem);
Chris@16 50 return invert ? T(-rem) : rem;
Chris@16 51 }
Chris@16 52
Chris@16 53 } // namespace detail
Chris@16 54
Chris@16 55 template <class T, class Policy>
Chris@101 56 inline typename tools::promote_args<T>::type sin_pi(T x, const Policy&)
Chris@16 57 {
Chris@16 58 typedef typename tools::promote_args<T>::type result_type;
Chris@101 59 typedef typename policies::evaluation<result_type, Policy>::type value_type;
Chris@101 60 typedef typename policies::normalise<
Chris@101 61 Policy,
Chris@101 62 policies::promote_float<false>,
Chris@101 63 policies::promote_double<false>,
Chris@101 64 policies::discrete_quantile<>,
Chris@101 65 policies::assert_undefined<> >::type forwarding_policy;
Chris@101 66 return policies::checked_narrowing_cast<result_type, forwarding_policy>(boost::math::detail::sin_pi_imp<value_type>(x, forwarding_policy()), "cos_pi");
Chris@16 67 }
Chris@16 68
Chris@16 69 template <class T>
Chris@16 70 inline typename tools::promote_args<T>::type sin_pi(T x)
Chris@16 71 {
Chris@16 72 return boost::math::sin_pi(x, policies::policy<>());
Chris@16 73 }
Chris@16 74
Chris@16 75 } // namespace math
Chris@16 76 } // namespace boost
Chris@16 77 #endif
Chris@16 78