epoc32/include/stdapis/boost/math/special_functions/sinhc.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
//  boost sinhc.hpp header file
williamr@2
     2
williamr@2
     3
//  (C) Copyright Hubert Holin 2001.
williamr@2
     4
//  Distributed under the Boost Software License, Version 1.0. (See
williamr@2
     5
//  accompanying file LICENSE_1_0.txt or copy at
williamr@2
     6
//  http://www.boost.org/LICENSE_1_0.txt)
williamr@2
     7
williamr@2
     8
// See http://www.boost.org for updates, documentation, and revision history.
williamr@2
     9
williamr@2
    10
#ifndef BOOST_SINHC_HPP
williamr@2
    11
#define BOOST_SINHC_HPP
williamr@2
    12
williamr@2
    13
williamr@2
    14
#include <cmath>
williamr@2
    15
#include <boost/limits.hpp>
williamr@2
    16
#include <string>
williamr@2
    17
#include <stdexcept>
williamr@2
    18
williamr@2
    19
williamr@2
    20
#include <boost/config.hpp>
williamr@2
    21
williamr@2
    22
williamr@2
    23
// These are the the "Hyperbolic Sinus Cardinal" functions.
williamr@2
    24
williamr@2
    25
namespace boost
williamr@2
    26
{
williamr@2
    27
    namespace math
williamr@2
    28
    {
williamr@2
    29
#if        defined(__GNUC__) && (__GNUC__ < 3)
williamr@2
    30
        // gcc 2.x ignores function scope using declarations,
williamr@2
    31
        // put them in the scope of the enclosing namespace instead:
williamr@2
    32
williamr@2
    33
        using    ::std::abs;
williamr@2
    34
        using    ::std::sqrt;
williamr@2
    35
        using    ::std::sinh;
williamr@2
    36
williamr@2
    37
        using    ::std::numeric_limits;
williamr@2
    38
#endif    /* defined(__GNUC__) && (__GNUC__ < 3) */
williamr@2
    39
williamr@2
    40
        // This is the "Hyperbolic Sinus Cardinal" of index Pi.
williamr@2
    41
williamr@2
    42
        template<typename T>
williamr@2
    43
        inline T    sinhc_pi(const T x)
williamr@2
    44
        {
williamr@2
    45
#ifdef    BOOST_NO_STDC_NAMESPACE
williamr@2
    46
            using    ::abs;
williamr@2
    47
            using    ::sinh;
williamr@2
    48
            using    ::sqrt;
williamr@2
    49
#else    /* BOOST_NO_STDC_NAMESPACE */
williamr@2
    50
            using    ::std::abs;
williamr@2
    51
            using    ::std::sinh;
williamr@2
    52
            using    ::std::sqrt;
williamr@2
    53
#endif    /* BOOST_NO_STDC_NAMESPACE */
williamr@2
    54
williamr@2
    55
            using    ::std::numeric_limits;
williamr@2
    56
williamr@2
    57
            static T const    taylor_0_bound = numeric_limits<T>::epsilon();
williamr@2
    58
            static T const    taylor_2_bound = sqrt(taylor_0_bound);
williamr@2
    59
            static T const    taylor_n_bound = sqrt(taylor_2_bound);
williamr@2
    60
williamr@2
    61
            if    (abs(x) >= taylor_n_bound)
williamr@2
    62
            {
williamr@2
    63
                return(sinh(x)/x);
williamr@2
    64
            }
williamr@2
    65
            else
williamr@2
    66
            {
williamr@2
    67
                // approximation by taylor series in x at 0 up to order 0
williamr@2
    68
                T    result = static_cast<T>(1);
williamr@2
    69
williamr@2
    70
                if    (abs(x) >= taylor_0_bound)
williamr@2
    71
                {
williamr@2
    72
                    T    x2 = x*x;
williamr@2
    73
williamr@2
    74
                    // approximation by taylor series in x at 0 up to order 2
williamr@2
    75
                    result += x2/static_cast<T>(6);
williamr@2
    76
williamr@2
    77
                    if    (abs(x) >= taylor_2_bound)
williamr@2
    78
                    {
williamr@2
    79
                        // approximation by taylor series in x at 0 up to order 4
williamr@2
    80
                        result += (x2*x2)/static_cast<T>(120);
williamr@2
    81
                    }
williamr@2
    82
                }
williamr@2
    83
williamr@2
    84
                return(result);
williamr@2
    85
            }
williamr@2
    86
        }
williamr@2
    87
williamr@2
    88
williamr@2
    89
#ifdef    BOOST_NO_TEMPLATE_TEMPLATES
williamr@2
    90
#else    /* BOOST_NO_TEMPLATE_TEMPLATES */
williamr@2
    91
        template<typename T, template<typename> class U>
williamr@2
    92
        inline U<T>    sinhc_pi(const U<T> x)
williamr@2
    93
        {
williamr@2
    94
#if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) || defined(__GNUC__)
williamr@2
    95
            using namespace std;
williamr@2
    96
#elif    defined(BOOST_NO_STDC_NAMESPACE)
williamr@2
    97
            using    ::abs;
williamr@2
    98
            using    ::sinh;
williamr@2
    99
            using    ::sqrt;
williamr@2
   100
#else    /* BOOST_NO_STDC_NAMESPACE */
williamr@2
   101
            using    ::std::abs;
williamr@2
   102
            using    ::std::sinh;
williamr@2
   103
            using    ::std::sqrt;
williamr@2
   104
#endif    /* BOOST_NO_STDC_NAMESPACE */
williamr@2
   105
williamr@2
   106
            using    ::std::numeric_limits;
williamr@2
   107
williamr@2
   108
            static T const    taylor_0_bound = numeric_limits<T>::epsilon();
williamr@2
   109
            static T const    taylor_2_bound = sqrt(taylor_0_bound);
williamr@2
   110
            static T const    taylor_n_bound = sqrt(taylor_2_bound);
williamr@2
   111
williamr@2
   112
            if    (abs(x) >= taylor_n_bound)
williamr@2
   113
            {
williamr@2
   114
                return(sinh(x)/x);
williamr@2
   115
            }
williamr@2
   116
            else
williamr@2
   117
            {
williamr@2
   118
                // approximation by taylor series in x at 0 up to order 0
williamr@2
   119
#ifdef __MWERKS__
williamr@2
   120
                U<T>    result = static_cast<U<T> >(1);
williamr@2
   121
#else
williamr@2
   122
                U<T>    result = U<T>(1);
williamr@2
   123
#endif
williamr@2
   124
williamr@2
   125
                if    (abs(x) >= taylor_0_bound)
williamr@2
   126
                {
williamr@2
   127
                    U<T>    x2 = x*x;
williamr@2
   128
williamr@2
   129
                    // approximation by taylor series in x at 0 up to order 2
williamr@2
   130
                    result += x2/static_cast<T>(6);
williamr@2
   131
williamr@2
   132
                    if    (abs(x) >= taylor_2_bound)
williamr@2
   133
                    {
williamr@2
   134
                        // approximation by taylor series in x at 0 up to order 4
williamr@2
   135
                        result += (x2*x2)/static_cast<T>(120);
williamr@2
   136
                    }
williamr@2
   137
                }
williamr@2
   138
williamr@2
   139
                return(result);
williamr@2
   140
            }
williamr@2
   141
        }
williamr@2
   142
#endif    /* BOOST_NO_TEMPLATE_TEMPLATES */
williamr@2
   143
    }
williamr@2
   144
}
williamr@2
   145
williamr@2
   146
#endif /* BOOST_SINHC_HPP */