epoc32/include/stdapis/boost/math/complex/asinh.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/boost/math/special_functions/asinh.hpp@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
//    boost asinh.hpp header file
williamr@2
     2
williamr@2
     3
//  (C) Copyright Eric Ford & 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_ASINH_HPP
williamr@2
    11
#define BOOST_ASINH_HPP
williamr@2
    12
williamr@2
    13
williamr@2
    14
#include <cmath>
williamr@2
    15
#include <limits>
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
// This is the inverse of the hyperbolic sine function.
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::log;
williamr@2
    36
        
williamr@2
    37
        using    ::std::numeric_limits;
williamr@2
    38
#endif
williamr@2
    39
        
williamr@2
    40
        template<typename T>
williamr@2
    41
        inline T    asinh(const T x)
williamr@2
    42
        {
williamr@2
    43
            using    ::std::abs;
williamr@2
    44
            using    ::std::sqrt;
williamr@2
    45
            using    ::std::log;
williamr@2
    46
            
williamr@2
    47
            using    ::std::numeric_limits;
williamr@2
    48
            
williamr@2
    49
            
williamr@2
    50
            T const            one = static_cast<T>(1);
williamr@2
    51
            T const            two = static_cast<T>(2);
williamr@2
    52
            
williamr@2
    53
            static T const    taylor_2_bound = sqrt(numeric_limits<T>::epsilon());
williamr@2
    54
            static T const    taylor_n_bound = sqrt(taylor_2_bound);
williamr@2
    55
            static T const    upper_taylor_2_bound = one/taylor_2_bound;
williamr@2
    56
            static T const    upper_taylor_n_bound = one/taylor_n_bound;
williamr@2
    57
            
williamr@2
    58
            if        (x >= +taylor_n_bound)
williamr@2
    59
            {
williamr@2
    60
                if        (x > upper_taylor_n_bound)
williamr@2
    61
                {
williamr@2
    62
                    if        (x > upper_taylor_2_bound)
williamr@2
    63
                    {
williamr@2
    64
                        // approximation by laurent series in 1/x at 0+ order from -1 to 0
williamr@2
    65
                        return( log( x * two) );
williamr@2
    66
                    }
williamr@2
    67
                    else
williamr@2
    68
                    {
williamr@2
    69
                        // approximation by laurent series in 1/x at 0+ order from -1 to 1
williamr@2
    70
                        return( log( x*two + (one/(x*two)) ) );
williamr@2
    71
                    }
williamr@2
    72
                }
williamr@2
    73
                else
williamr@2
    74
                {
williamr@2
    75
                    return( log( x + sqrt(x*x+one) ) );
williamr@2
    76
                }
williamr@2
    77
            }
williamr@2
    78
            else if    (x <= -taylor_n_bound)
williamr@2
    79
            {
williamr@2
    80
                return(-asinh(-x));
williamr@2
    81
            }
williamr@2
    82
            else
williamr@2
    83
            {
williamr@2
    84
                // approximation by taylor series in x at 0 up to order 2
williamr@2
    85
                T    result = x;
williamr@2
    86
                
williamr@2
    87
                if    (abs(x) >= taylor_2_bound)
williamr@2
    88
                {
williamr@2
    89
                    T    x3 = x*x*x;
williamr@2
    90
                    
williamr@2
    91
                    // approximation by taylor series in x at 0 up to order 4
williamr@2
    92
                    result -= x3/static_cast<T>(6);
williamr@2
    93
                }
williamr@2
    94
                
williamr@2
    95
                return(result);
williamr@2
    96
            }
williamr@2
    97
        }
williamr@2
    98
    }
williamr@2
    99
}
williamr@2
   100
williamr@2
   101
#endif /* BOOST_ASINH_HPP */