Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:23

0001 //  Copyright (c) 2007 John Maddock
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_MATH_SIN_PI_HPP
0007 #define BOOST_MATH_SIN_PI_HPP
0008 
0009 #ifdef _MSC_VER
0010 #pragma once
0011 #endif
0012 
0013 #include <cmath>
0014 #include <limits>
0015 #include <boost/math/tools/config.hpp>
0016 #include <boost/math/special_functions/math_fwd.hpp>
0017 #include <boost/math/special_functions/trunc.hpp>
0018 #include <boost/math/tools/promotion.hpp>
0019 #include <boost/math/constants/constants.hpp>
0020 
0021 namespace boost{ namespace math{ namespace detail{
0022 
0023 template <class T, class Policy>
0024 inline T sin_pi_imp(T x, const Policy& pol)
0025 {
0026    BOOST_MATH_STD_USING // ADL of std names
0027    if(x < 0)
0028       return -sin_pi_imp(T(-x), pol);
0029    // sin of pi*x:
0030    if(x < T(0.5))
0031       return sin(constants::pi<T>() * x);
0032    bool invert;
0033    if(x < 1)
0034    {
0035       invert = true;
0036       x = -x;
0037    }
0038    else
0039       invert = false;
0040 
0041    T rem = floor(x);
0042    if(abs(floor(rem/2)*2 - rem) > std::numeric_limits<T>::epsilon())
0043    {
0044       invert = !invert;
0045    }
0046    rem = x - rem;
0047    if(rem > 0.5f)
0048       rem = 1 - rem;
0049    if(rem == 0.5f)
0050       return static_cast<T>(invert ? -1 : 1);
0051    
0052    rem = sin(constants::pi<T>() * rem);
0053    return invert ? T(-rem) : rem;
0054 }
0055 
0056 } // namespace detail
0057 
0058 template <class T, class Policy>
0059 inline typename tools::promote_args<T>::type sin_pi(T x, const Policy&)
0060 {
0061    typedef typename tools::promote_args<T>::type result_type;
0062    typedef typename policies::evaluation<result_type, Policy>::type value_type;
0063    typedef typename policies::normalise<
0064       Policy,
0065       policies::promote_float<false>,
0066       policies::promote_double<false>,
0067       policies::discrete_quantile<>,
0068       policies::assert_undefined<>,
0069       // We want to ignore overflows since the result is in [-1,1] and the 
0070       // check slows the code down considerably.
0071       policies::overflow_error<policies::ignore_error> >::type forwarding_policy;
0072    return policies::checked_narrowing_cast<result_type, forwarding_policy>(boost::math::detail::sin_pi_imp<value_type>(x, forwarding_policy()), "sin_pi");
0073 }
0074 
0075 template <class T>
0076 inline typename tools::promote_args<T>::type sin_pi(T x)
0077 {
0078    return boost::math::sin_pi(x, policies::policy<>());
0079 }
0080 
0081 } // namespace math
0082 } // namespace boost
0083 #endif
0084