Back to home page

EIC code displayed by LXR

 
 

    


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

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