Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/math/special_functions/sinc.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //  boost sinc.hpp header file
0002 
0003 //  (C) Copyright Hubert Holin 2001.
0004 //  Distributed under the Boost Software License, Version 1.0. (See
0005 //  accompanying file LICENSE_1_0.txt or copy at
0006 //  http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 // See http://www.boost.org for updates, documentation, and revision history.
0009 
0010 #ifndef BOOST_SINC_HPP
0011 #define BOOST_SINC_HPP
0012 
0013 
0014 #ifdef _MSC_VER
0015 #pragma once
0016 #endif
0017 
0018 #include <boost/math/tools/config.hpp>
0019 #include <boost/math/tools/precision.hpp>
0020 #include <boost/math/tools/promotion.hpp>
0021 #include <boost/math/policies/policy.hpp>
0022 #include <boost/math/special_functions/fpclassify.hpp>
0023 
0024 #ifndef BOOST_MATH_HAS_NVRTC
0025 #include <boost/math/special_functions/math_fwd.hpp>
0026 #endif
0027 
0028 // These are the the "Sinus Cardinal" functions.
0029 
0030 namespace boost
0031 {
0032     namespace math
0033     {
0034        namespace detail
0035        {
0036         // This is the "Sinus Cardinal" of index Pi.
0037 
0038         template<typename T>
0039         BOOST_MATH_GPU_ENABLED inline T    sinc_pi_imp(const T x)
0040         {
0041             BOOST_MATH_STD_USING
0042 
0043             if ((boost::math::isinf)(x))
0044             {
0045                return 0;
0046             }
0047             else if (abs(x) >= T(3.3) * tools::forth_root_epsilon<T>())
0048             {
0049                 return(sin(x)/x);
0050             }
0051             else
0052             {
0053                 // |x| < (eps*120)^(1/4)
0054                 return 1 - x * x / 6;
0055             }
0056         }
0057 
0058        } // namespace detail
0059 
0060        template <class T>
0061        BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type sinc_pi(T x)
0062        {
0063           typedef typename tools::promote_args<T>::type result_type;
0064           return detail::sinc_pi_imp(static_cast<result_type>(x));
0065        }
0066 
0067        template <class T, class Policy>
0068        BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type sinc_pi(T x, const Policy&)
0069        {
0070           typedef typename tools::promote_args<T>::type result_type;
0071           return detail::sinc_pi_imp(static_cast<result_type>(x));
0072        }
0073 
0074         template<typename T, template<typename> class U>
0075         BOOST_MATH_GPU_ENABLED inline U<T>    sinc_pi(const U<T> x)
0076         {
0077             BOOST_MATH_STD_USING
0078 
0079             T const    taylor_0_bound = tools::epsilon<T>();
0080             T const    taylor_2_bound = tools::root_epsilon<T>();
0081             T const    taylor_n_bound = tools::forth_root_epsilon<T>();
0082 
0083             if    (abs(x) >= taylor_n_bound)
0084             {
0085                 return(sin(x)/x);
0086             }
0087             else
0088             {
0089                 // approximation by taylor series in x at 0 up to order 0
0090                 #ifdef __MWERKS__
0091                 U<T>    result = static_cast<U<T> >(1);
0092                 #else
0093                 U<T>    result = U<T>(1);
0094                 #endif
0095 
0096                 if    (abs(x) >= taylor_0_bound)
0097                 {
0098                     U<T>    x2 = x*x;
0099 
0100                     // approximation by taylor series in x at 0 up to order 2
0101                     result -= x2/static_cast<T>(6);
0102 
0103                     if    (abs(x) >= taylor_2_bound)
0104                     {
0105                         // approximation by taylor series in x at 0 up to order 4
0106                         result += (x2*x2)/static_cast<T>(120);
0107                     }
0108                 }
0109 
0110                 return(result);
0111             }
0112         }
0113 
0114         template<typename T, template<typename> class U, class Policy>
0115         BOOST_MATH_GPU_ENABLED inline U<T>    sinc_pi(const U<T> x, const Policy&)
0116         {
0117            return sinc_pi(x);
0118         }
0119     }
0120 }
0121 
0122 #endif /* BOOST_SINC_HPP */
0123