Warning, file /include/boost/math/special_functions/sin_pi.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_MATH_SIN_PI_HPP
0008 #define BOOST_MATH_SIN_PI_HPP
0009
0010 #ifdef _MSC_VER
0011 #pragma once
0012 #endif
0013
0014 #include <boost/math/tools/config.hpp>
0015
0016 #ifndef BOOST_MATH_HAS_NVRTC
0017
0018 #include <cmath>
0019 #include <limits>
0020 #include <type_traits>
0021 #include <boost/math/tools/numeric_limits.hpp>
0022 #include <boost/math/special_functions/math_fwd.hpp>
0023 #include <boost/math/special_functions/trunc.hpp>
0024 #include <boost/math/tools/promotion.hpp>
0025 #include <boost/math/constants/constants.hpp>
0026
0027 namespace boost{ namespace math{ namespace detail{
0028
0029 template <class T, class Policy>
0030 BOOST_MATH_GPU_ENABLED inline T sin_pi_imp(T x, const Policy&)
0031 {
0032 BOOST_MATH_STD_USING
0033
0034 if(x < T(0.5))
0035 return sin(constants::pi<T>() * x);
0036 bool invert;
0037 if(x < 1)
0038 {
0039 invert = true;
0040 x = -x;
0041 }
0042 else
0043 invert = false;
0044
0045 T rem = floor(x);
0046 if(abs(floor(rem/2)*2 - rem) > boost::math::numeric_limits<T>::epsilon())
0047 {
0048 invert = !invert;
0049 }
0050 rem = x - rem;
0051 if(rem > 0.5f)
0052 rem = 1 - rem;
0053 if(rem == 0.5f)
0054 return static_cast<T>(invert ? -1 : 1);
0055
0056 rem = sin(constants::pi<T>() * rem);
0057 return invert ? T(-rem) : rem;
0058 }
0059
0060 template <class T, class Policy>
0061 BOOST_MATH_GPU_ENABLED inline T sin_pi_dispatch(T x, const Policy& pol)
0062 {
0063 if (x < T(0))
0064 {
0065 return -sin_pi_imp(T(-x), pol);
0066 }
0067 else
0068 {
0069 return sin_pi_imp(T(x), pol);
0070 }
0071 }
0072
0073 }
0074
0075 template <class T, class Policy>
0076 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type sin_pi(T x, const Policy&)
0077 {
0078 typedef typename tools::promote_args<T>::type result_type;
0079 typedef typename policies::evaluation<result_type, Policy>::type value_type;
0080 typedef typename policies::normalise<
0081 Policy,
0082 policies::promote_float<false>,
0083 policies::promote_double<false>,
0084 policies::discrete_quantile<>,
0085 policies::assert_undefined<>,
0086
0087
0088 policies::overflow_error<policies::ignore_error> >::type forwarding_policy;
0089 return policies::checked_narrowing_cast<result_type, forwarding_policy>(boost::math::detail::sin_pi_dispatch<value_type>(x, forwarding_policy()), "sin_pi");
0090 }
0091
0092 template <class T>
0093 inline typename tools::promote_args<T>::type sin_pi(T x)
0094 {
0095 return boost::math::sin_pi(x, policies::policy<>());
0096 }
0097
0098 }
0099 }
0100
0101 #else
0102
0103 namespace boost {
0104 namespace math {
0105
0106 template <typename T>
0107 BOOST_MATH_GPU_ENABLED auto sin_pi(T x)
0108 {
0109 return ::sinpi(x);
0110 }
0111
0112 template <>
0113 BOOST_MATH_GPU_ENABLED auto sin_pi(float x)
0114 {
0115 return ::sinpif(x);
0116 }
0117
0118 template <typename T, typename Policy>
0119 BOOST_MATH_GPU_ENABLED auto sin_pi(T x, const Policy&)
0120 {
0121 return ::sinpi(x);
0122 }
0123
0124 template <typename Policy>
0125 BOOST_MATH_GPU_ENABLED auto sin_pi(float x, const Policy&)
0126 {
0127 return ::sinpif(x);
0128 }
0129
0130 }
0131 }
0132
0133 #endif
0134
0135 #endif
0136