Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 08:17:22

0001 //  boost sinhc.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_SINHC_HPP
0011 #define BOOST_SINHC_HPP
0012 
0013 
0014 #ifdef _MSC_VER
0015 #pragma once
0016 #endif
0017 
0018 #include <boost/math/tools/precision.hpp>
0019 #include <boost/math/policies/error_handling.hpp>
0020 #include <boost/math/special_functions/math_fwd.hpp>
0021 #include <boost/math/special_functions/fpclassify.hpp>
0022 #include <limits>
0023 #include <string>
0024 #include <stdexcept>
0025 #include <cmath>
0026 
0027 // These are the the "Hyperbolic Sinus Cardinal" functions.
0028 
0029 namespace boost
0030 {
0031     namespace math
0032     {
0033        namespace detail
0034        {
0035         // This is the "Hyperbolic Sinus Cardinal" of index Pi.
0036 
0037         template<typename T, typename Policy>
0038         inline T    sinhc_pi_imp(const T x, const Policy&)
0039         {
0040             using    ::std::abs;
0041             using    ::std::sinh;
0042             using    ::std::sqrt;
0043 
0044             static T const    taylor_0_bound = tools::epsilon<T>();
0045             static T const    taylor_2_bound = sqrt(taylor_0_bound);
0046             static T const    taylor_n_bound = sqrt(taylor_2_bound);
0047 
0048             if((boost::math::isinf)(x))
0049             {
0050                return policies::raise_overflow_error<T>("sinhc(%1%)", nullptr, Policy());
0051             }
0052             if    (abs(x) >= taylor_n_bound)
0053             {
0054                 return(sinh(x)/x);
0055             }
0056             else
0057             {
0058                 // approximation by taylor series in x at 0 up to order 0
0059                 T    result = static_cast<T>(1);
0060 
0061                 if    (abs(x) >= taylor_0_bound)
0062                 {
0063                     T    x2 = x*x;
0064 
0065                     // approximation by taylor series in x at 0 up to order 2
0066                     result += x2/static_cast<T>(6);
0067 
0068                     if    (abs(x) >= taylor_2_bound)
0069                     {
0070                         // approximation by taylor series in x at 0 up to order 4
0071                         result += (x2*x2)/static_cast<T>(120);
0072                     }
0073                 }
0074 
0075                 return(result);
0076             }
0077         }
0078 
0079        } // namespace detail
0080 
0081        template <class T, class Policy>
0082        inline typename tools::promote_args<T>::type sinhc_pi(T x, const Policy& pol)
0083        {
0084           typedef typename tools::promote_args<T>::type result_type;
0085           return policies::checked_narrowing_cast<T, Policy>(detail::sinhc_pi_imp(static_cast<result_type>(x), pol), "sinhc(%1%)");
0086        }
0087 
0088        template <class T>
0089        inline typename tools::promote_args<T>::type sinhc_pi(T x)
0090        {
0091           typedef typename tools::promote_args<T>::type result_type;
0092           return sinhc_pi(static_cast<result_type>(x), policies::policy<>());
0093        }
0094 
0095         template<typename T, template<typename> class U>
0096         inline U<T>    sinhc_pi(const U<T> x)
0097         {
0098             using std::abs;
0099             using std::sinh;
0100             using std::sqrt;
0101 
0102             using    ::std::numeric_limits;
0103 
0104             static T const    taylor_0_bound = tools::epsilon<T>();
0105             static T const    taylor_2_bound = sqrt(taylor_0_bound);
0106             static T const    taylor_n_bound = sqrt(taylor_2_bound);
0107 
0108             if    (abs(x) >= taylor_n_bound)
0109             {
0110                 return(sinh(x)/x);
0111             }
0112             else
0113             {
0114                 // approximation by taylor series in x at 0 up to order 0
0115 #ifdef __MWERKS__
0116                 U<T>    result = static_cast<U<T> >(1);
0117 #else
0118                 U<T>    result = U<T>(1);
0119 #endif
0120 
0121                 if    (abs(x) >= taylor_0_bound)
0122                 {
0123                     U<T>    x2 = x*x;
0124 
0125                     // approximation by taylor series in x at 0 up to order 2
0126                     result += x2/static_cast<T>(6);
0127 
0128                     if    (abs(x) >= taylor_2_bound)
0129                     {
0130                         // approximation by taylor series in x at 0 up to order 4
0131                         result += (x2*x2)/static_cast<T>(120);
0132                     }
0133                 }
0134 
0135                 return(result);
0136             }
0137         }
0138     }
0139 }
0140 
0141 #endif /* BOOST_SINHC_HPP */
0142