Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 08:15:37

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/policies/policy.hpp>
0021 #include <boost/math/special_functions/math_fwd.hpp>
0022 #include <boost/math/special_functions/fpclassify.hpp>
0023 #include <limits>
0024 #include <string>
0025 #include <stdexcept>
0026 #include <cmath>
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         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) >= 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        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        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         inline U<T>    sinc_pi(const U<T> x)
0076         {
0077             BOOST_MATH_STD_USING
0078             using    ::std::numeric_limits;
0079 
0080             T const    taylor_0_bound = tools::epsilon<T>();
0081             T const    taylor_2_bound = tools::root_epsilon<T>();
0082             T const    taylor_n_bound = tools::forth_root_epsilon<T>();
0083 
0084             if    (abs(x) >= taylor_n_bound)
0085             {
0086                 return(sin(x)/x);
0087             }
0088             else
0089             {
0090                 // approximation by taylor series in x at 0 up to order 0
0091 #ifdef __MWERKS__
0092                 U<T>    result = static_cast<U<T> >(1);
0093 #else
0094                 U<T>    result = U<T>(1);
0095 #endif
0096 
0097                 if    (abs(x) >= taylor_0_bound)
0098                 {
0099                     U<T>    x2 = x*x;
0100 
0101                     // approximation by taylor series in x at 0 up to order 2
0102                     result -= x2/static_cast<T>(6);
0103 
0104                     if    (abs(x) >= taylor_2_bound)
0105                     {
0106                         // approximation by taylor series in x at 0 up to order 4
0107                         result += (x2*x2)/static_cast<T>(120);
0108                     }
0109                 }
0110 
0111                 return(result);
0112             }
0113         }
0114 
0115         template<typename T, template<typename> class U, class Policy>
0116         inline U<T>    sinc_pi(const U<T> x, const Policy&)
0117         {
0118            return sinc_pi(x);
0119         }
0120     }
0121 }
0122 
0123 #endif /* BOOST_SINC_HPP */
0124