epoc32/include/stdapis/boost/math/complex/acosh.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/acosh.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 2001 & Hubert Holin.
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_ACOSH_HPP
williamr@2
    11
#define BOOST_ACOSH_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 cosine 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
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
williamr@2
    41
        // This is the main fare
williamr@2
    42
        
williamr@2
    43
        template<typename T>
williamr@2
    44
        inline T    acosh(const T x)
williamr@2
    45
        {
williamr@2
    46
            using    ::std::abs;
williamr@2
    47
            using    ::std::sqrt;
williamr@2
    48
            using    ::std::log;
williamr@2
    49
            
williamr@2
    50
            using    ::std::numeric_limits;
williamr@2
    51
            
williamr@2
    52
            
williamr@2
    53
            T const    one = static_cast<T>(1);
williamr@2
    54
            T const    two = static_cast<T>(2);
williamr@2
    55
            
williamr@2
    56
            static T const    taylor_2_bound = sqrt(numeric_limits<T>::epsilon());
williamr@2
    57
            static T const    taylor_n_bound = sqrt(taylor_2_bound);
williamr@2
    58
            static T const    upper_taylor_2_bound = one/taylor_2_bound;
williamr@2
    59
            
williamr@2
    60
            if        (x < one)
williamr@2
    61
            {
williamr@2
    62
                if    (numeric_limits<T>::has_quiet_NaN)
williamr@2
    63
                {
williamr@2
    64
                    return(numeric_limits<T>::quiet_NaN());
williamr@2
    65
                }
williamr@2
    66
                else
williamr@2
    67
                {
williamr@2
    68
                    ::std::string        error_reporting("Argument to atanh is strictly greater than +1 or strictly smaller than -1!");
williamr@2
    69
                    ::std::domain_error  bad_argument(error_reporting);
williamr@2
    70
                    
williamr@2
    71
                    throw(bad_argument);
williamr@2
    72
                }
williamr@2
    73
            }
williamr@2
    74
            else if    (x >= taylor_n_bound)
williamr@2
    75
            {
williamr@2
    76
                if    (x > upper_taylor_2_bound)
williamr@2
    77
                {
williamr@2
    78
                    // approximation by laurent series in 1/x at 0+ order from -1 to 0
williamr@2
    79
                    return( log( x*two) );
williamr@2
    80
                }
williamr@2
    81
                else
williamr@2
    82
                {
williamr@2
    83
                    return( log( x + sqrt(x*x-one) ) );
williamr@2
    84
                }
williamr@2
    85
            }
williamr@2
    86
            else
williamr@2
    87
            {
williamr@2
    88
                T    y = sqrt(x-one);
williamr@2
    89
                
williamr@2
    90
                // approximation by taylor series in y at 0 up to order 2
williamr@2
    91
                T    result = y;
williamr@2
    92
                
williamr@2
    93
                if    (y >= taylor_2_bound)
williamr@2
    94
                {
williamr@2
    95
                    T    y3 = y*y*y;
williamr@2
    96
                    
williamr@2
    97
                    // approximation by taylor series in y at 0 up to order 4
williamr@2
    98
                    result -= y3/static_cast<T>(12);
williamr@2
    99
                }
williamr@2
   100
                
williamr@2
   101
                return(sqrt(static_cast<T>(2))*result);
williamr@2
   102
            }
williamr@2
   103
        }
williamr@2
   104
#else
williamr@2
   105
        // These are implementation details (for main fare see below)
williamr@2
   106
        
williamr@2
   107
        namespace detail
williamr@2
   108
        {
williamr@2
   109
            template    <
williamr@2
   110
                            typename T,
williamr@2
   111
                            bool QuietNanSupported
williamr@2
   112
                        >
williamr@2
   113
            struct    acosh_helper2_t
williamr@2
   114
            {
williamr@2
   115
                static T    get_NaN()
williamr@2
   116
                {
williamr@2
   117
                    return(::std::numeric_limits<T>::quiet_NaN());
williamr@2
   118
                }
williamr@2
   119
            };  // boost::detail::acosh_helper2_t
williamr@2
   120
            
williamr@2
   121
            
williamr@2
   122
            template<typename T>
williamr@2
   123
            struct    acosh_helper2_t<T, false>
williamr@2
   124
            {
williamr@2
   125
                static T    get_NaN()
williamr@2
   126
                {
williamr@2
   127
                    ::std::string        error_reporting("Argument to acosh is greater than or equal to +1!");
williamr@2
   128
                    ::std::domain_error  bad_argument(error_reporting);
williamr@2
   129
                    
williamr@2
   130
                    throw(bad_argument);
williamr@2
   131
                }
williamr@2
   132
            };  // boost::detail::acosh_helper2_t
williamr@2
   133
        
williamr@2
   134
        }  // boost::detail
williamr@2
   135
        
williamr@2
   136
        
williamr@2
   137
        // This is the main fare
williamr@2
   138
        
williamr@2
   139
        template<typename T>
williamr@2
   140
        inline T    acosh(const T x)
williamr@2
   141
        {
williamr@2
   142
            using    ::std::abs;
williamr@2
   143
            using    ::std::sqrt;
williamr@2
   144
            using    ::std::log;
williamr@2
   145
            
williamr@2
   146
            using    ::std::numeric_limits;
williamr@2
   147
            
williamr@2
   148
            typedef    detail::acosh_helper2_t<T, std::numeric_limits<T>::has_quiet_NaN>    helper2_type;
williamr@2
   149
            
williamr@2
   150
            
williamr@2
   151
            T const    one = static_cast<T>(1);
williamr@2
   152
            T const    two = static_cast<T>(2);
williamr@2
   153
            
williamr@2
   154
            static T const    taylor_2_bound = sqrt(numeric_limits<T>::epsilon());
williamr@2
   155
            static T const    taylor_n_bound = sqrt(taylor_2_bound);
williamr@2
   156
            static T const    upper_taylor_2_bound = one/taylor_2_bound;
williamr@2
   157
            
williamr@2
   158
            if        (x < one)
williamr@2
   159
            {
williamr@2
   160
                return(helper2_type::get_NaN());
williamr@2
   161
            }
williamr@2
   162
            else if    (x >= taylor_n_bound)
williamr@2
   163
            {
williamr@2
   164
                if    (x > upper_taylor_2_bound)
williamr@2
   165
                {
williamr@2
   166
                    // approximation by laurent series in 1/x at 0+ order from -1 to 0
williamr@2
   167
                    return( log( x*two) );
williamr@2
   168
                }
williamr@2
   169
                else
williamr@2
   170
                {
williamr@2
   171
                    return( log( x + sqrt(x*x-one) ) );
williamr@2
   172
                }
williamr@2
   173
            }
williamr@2
   174
            else
williamr@2
   175
            {
williamr@2
   176
                T    y = sqrt(x-one);
williamr@2
   177
                
williamr@2
   178
                // approximation by taylor series in y at 0 up to order 2
williamr@2
   179
                T    result = y;
williamr@2
   180
                
williamr@2
   181
                if    (y >= taylor_2_bound)
williamr@2
   182
                {
williamr@2
   183
                    T    y3 = y*y*y;
williamr@2
   184
                    
williamr@2
   185
                    // approximation by taylor series in y at 0 up to order 4
williamr@2
   186
                    result -= y3/static_cast<T>(12);
williamr@2
   187
                }
williamr@2
   188
                
williamr@2
   189
                return(sqrt(static_cast<T>(2))*result);
williamr@2
   190
            }
williamr@2
   191
        }
williamr@2
   192
#endif /* defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) */
williamr@2
   193
    }
williamr@2
   194
}
williamr@2
   195
williamr@2
   196
#endif /* BOOST_ACOSH_HPP */
williamr@2
   197
williamr@2
   198