~tsarev/boostdc/cmake

« back to all changes in this revision

Viewing changes to boost/boost/math/special_functions/acosh.hpp

  • Committer: bigmuscle
  • Date: 2010-05-08 08:47:15 UTC
  • Revision ID: svn-v4:5fb55d53-692c-0410-a46a-e90ab66e00ee:trunk:497
removed old boost version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//    boost asinh.hpp header file
2
 
 
3
 
//  (C) Copyright Eric Ford 2001 & Hubert Holin.
4
 
//  (C) Copyright John Maddock 2008.
5
 
//  Distributed under the Boost Software License, Version 1.0. (See
6
 
//  accompanying file LICENSE_1_0.txt or copy at
7
 
//  http://www.boost.org/LICENSE_1_0.txt)
8
 
 
9
 
// See http://www.boost.org for updates, documentation, and revision history.
10
 
 
11
 
#ifndef BOOST_ACOSH_HPP
12
 
#define BOOST_ACOSH_HPP
13
 
 
14
 
#ifdef _MSC_VER
15
 
#pragma once
16
 
#endif
17
 
 
18
 
#include <boost/config/no_tr1/cmath.hpp>
19
 
#include <boost/config.hpp>
20
 
#include <boost/math/tools/precision.hpp>
21
 
#include <boost/math/policies/error_handling.hpp>
22
 
#include <boost/math/special_functions/math_fwd.hpp>
23
 
#include <boost/math/special_functions/log1p.hpp>
24
 
 
25
 
// This is the inverse of the hyperbolic cosine function.
26
 
 
27
 
namespace boost
28
 
{
29
 
    namespace math
30
 
    {
31
 
       namespace detail
32
 
       {
33
 
#if defined(__GNUC__) && (__GNUC__ < 3)
34
 
        // gcc 2.x ignores function scope using declarations,
35
 
        // put them in the scope of the enclosing namespace instead:
36
 
        
37
 
        using    ::std::abs;
38
 
        using    ::std::sqrt;
39
 
        using    ::std::log;
40
 
        
41
 
        using    ::std::numeric_limits;
42
 
#endif
43
 
        
44
 
        template<typename T, typename Policy>
45
 
        inline T    acosh_imp(const T x, const Policy& pol)
46
 
        {
47
 
            BOOST_MATH_STD_USING
48
 
            
49
 
            if(x < 1)
50
 
            {
51
 
               return policies::raise_domain_error<T>(
52
 
                  "boost::math::acosh<%1%>(%1%)",
53
 
                  "acosh requires x >= 1, but got x = %1%.", x, pol);
54
 
            }
55
 
            else if    ((x - 1) >= tools::root_epsilon<T>())
56
 
            {
57
 
                if    (x > 1 / tools::root_epsilon<T>())
58
 
                {
59
 
                    // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/06/01/0001/
60
 
                    // approximation by laurent series in 1/x at 0+ order from -1 to 0
61
 
                    return( log( x * 2) );
62
 
                }
63
 
                else if(x < 1.5f)
64
 
                {
65
 
                   // This is just a rearrangement of the standard form below
66
 
                   // devised to minimse loss of precision when x ~ 1:
67
 
                   T y = x - 1;
68
 
                   return boost::math::log1p(y + sqrt(y * y + 2 * y), pol);
69
 
                }
70
 
                else
71
 
                {
72
 
                    // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/
73
 
                    return( log( x + sqrt(x * x - 1) ) );
74
 
                }
75
 
            }
76
 
            else
77
 
            {
78
 
                // see http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/04/01/0001/
79
 
                T y = x - 1;
80
 
                
81
 
                // approximation by taylor series in y at 0 up to order 2
82
 
                T result = sqrt(2 * y) * (1 + y /12 + 3 * y * y / 160);
83
 
                return result;
84
 
            }
85
 
        }
86
 
       }
87
 
 
88
 
        template<typename T, typename Policy>
89
 
        inline typename tools::promote_args<T>::type acosh(T x, const Policy&)
90
 
        {
91
 
            typedef typename tools::promote_args<T>::type result_type;
92
 
            typedef typename policies::evaluation<result_type, Policy>::type value_type;
93
 
            typedef typename policies::normalise<
94
 
               Policy, 
95
 
               policies::promote_float<false>, 
96
 
               policies::promote_double<false>, 
97
 
               policies::discrete_quantile<>,
98
 
               policies::assert_undefined<> >::type forwarding_policy;
99
 
           return policies::checked_narrowing_cast<result_type, forwarding_policy>(
100
 
              detail::acosh_imp(static_cast<value_type>(x), forwarding_policy()),
101
 
              "boost::math::acosh<%1%>(%1%)");
102
 
        }
103
 
        template<typename T>
104
 
        inline typename tools::promote_args<T>::type acosh(T x)
105
 
        {
106
 
           return boost::math::acosh(x, policies::policy<>());
107
 
        }
108
 
 
109
 
    }
110
 
}
111
 
 
112
 
#endif /* BOOST_ACOSH_HPP */
113
 
 
114