williamr@2: // boost sinhc.hpp header file williamr@2: williamr@2: // (C) Copyright Hubert Holin 2001. williamr@2: // Distributed under the Boost Software License, Version 1.0. (See williamr@2: // accompanying file LICENSE_1_0.txt or copy at williamr@2: // http://www.boost.org/LICENSE_1_0.txt) williamr@2: williamr@2: // See http://www.boost.org for updates, documentation, and revision history. williamr@2: williamr@2: #ifndef BOOST_SINHC_HPP williamr@2: #define BOOST_SINHC_HPP williamr@2: williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: williamr@2: #include williamr@2: williamr@2: williamr@2: // These are the the "Hyperbolic Sinus Cardinal" functions. williamr@2: williamr@2: namespace boost williamr@2: { williamr@2: namespace math williamr@2: { williamr@2: #if defined(__GNUC__) && (__GNUC__ < 3) williamr@2: // gcc 2.x ignores function scope using declarations, williamr@2: // put them in the scope of the enclosing namespace instead: williamr@2: williamr@2: using ::std::abs; williamr@2: using ::std::sqrt; williamr@2: using ::std::sinh; williamr@2: williamr@2: using ::std::numeric_limits; williamr@2: #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ williamr@2: williamr@2: // This is the "Hyperbolic Sinus Cardinal" of index Pi. williamr@2: williamr@2: template williamr@2: inline T sinhc_pi(const T x) williamr@2: { williamr@2: #ifdef BOOST_NO_STDC_NAMESPACE williamr@2: using ::abs; williamr@2: using ::sinh; williamr@2: using ::sqrt; williamr@2: #else /* BOOST_NO_STDC_NAMESPACE */ williamr@2: using ::std::abs; williamr@2: using ::std::sinh; williamr@2: using ::std::sqrt; williamr@2: #endif /* BOOST_NO_STDC_NAMESPACE */ williamr@2: williamr@2: using ::std::numeric_limits; williamr@2: williamr@2: static T const taylor_0_bound = numeric_limits::epsilon(); williamr@2: static T const taylor_2_bound = sqrt(taylor_0_bound); williamr@2: static T const taylor_n_bound = sqrt(taylor_2_bound); williamr@2: williamr@2: if (abs(x) >= taylor_n_bound) williamr@2: { williamr@2: return(sinh(x)/x); williamr@2: } williamr@2: else williamr@2: { williamr@2: // approximation by taylor series in x at 0 up to order 0 williamr@2: T result = static_cast(1); williamr@2: williamr@2: if (abs(x) >= taylor_0_bound) williamr@2: { williamr@2: T x2 = x*x; williamr@2: williamr@2: // approximation by taylor series in x at 0 up to order 2 williamr@2: result += x2/static_cast(6); williamr@2: williamr@2: if (abs(x) >= taylor_2_bound) williamr@2: { williamr@2: // approximation by taylor series in x at 0 up to order 4 williamr@2: result += (x2*x2)/static_cast(120); williamr@2: } williamr@2: } williamr@2: williamr@2: return(result); williamr@2: } williamr@2: } williamr@2: williamr@2: williamr@2: #ifdef BOOST_NO_TEMPLATE_TEMPLATES williamr@2: #else /* BOOST_NO_TEMPLATE_TEMPLATES */ williamr@2: template class U> williamr@2: inline U sinhc_pi(const U x) williamr@2: { williamr@2: #if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) || defined(__GNUC__) williamr@2: using namespace std; williamr@2: #elif defined(BOOST_NO_STDC_NAMESPACE) williamr@2: using ::abs; williamr@2: using ::sinh; williamr@2: using ::sqrt; williamr@2: #else /* BOOST_NO_STDC_NAMESPACE */ williamr@2: using ::std::abs; williamr@2: using ::std::sinh; williamr@2: using ::std::sqrt; williamr@2: #endif /* BOOST_NO_STDC_NAMESPACE */ williamr@2: williamr@2: using ::std::numeric_limits; williamr@2: williamr@2: static T const taylor_0_bound = numeric_limits::epsilon(); williamr@2: static T const taylor_2_bound = sqrt(taylor_0_bound); williamr@2: static T const taylor_n_bound = sqrt(taylor_2_bound); williamr@2: williamr@2: if (abs(x) >= taylor_n_bound) williamr@2: { williamr@2: return(sinh(x)/x); williamr@2: } williamr@2: else williamr@2: { williamr@2: // approximation by taylor series in x at 0 up to order 0 williamr@2: #ifdef __MWERKS__ williamr@2: U result = static_cast >(1); williamr@2: #else williamr@2: U result = U(1); williamr@2: #endif williamr@2: williamr@2: if (abs(x) >= taylor_0_bound) williamr@2: { williamr@2: U x2 = x*x; williamr@2: williamr@2: // approximation by taylor series in x at 0 up to order 2 williamr@2: result += x2/static_cast(6); williamr@2: williamr@2: if (abs(x) >= taylor_2_bound) williamr@2: { williamr@2: // approximation by taylor series in x at 0 up to order 4 williamr@2: result += (x2*x2)/static_cast(120); williamr@2: } williamr@2: } williamr@2: williamr@2: return(result); williamr@2: } williamr@2: } williamr@2: #endif /* BOOST_NO_TEMPLATE_TEMPLATES */ williamr@2: } williamr@2: } williamr@2: williamr@2: #endif /* BOOST_SINHC_HPP */