Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/math/special_functions/asinh_test.hpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 2.1 KB
Line 
1// unit test file asinh.hpp for the special functions test suite
2
3//  (C) Copyright Hubert Holin 2003.
4//  Distributed under the Boost Software License, Version 1.0. (See
5//  accompanying file LICENSE_1_0.txt or copy at
6//  http://www.boost.org/LICENSE_1_0.txt)
7
8
9#include <functional>
10#include <iomanip>
11#include <iostream>
12
13
14#include <boost/math/special_functions/asinh.hpp>
15
16
17#include <boost/test/unit_test.hpp>
18
19
20template<typename T>
21T    asinh_error_evaluator(T x)
22{
23    using    ::std::abs;
24    using    ::std::sinh;
25    using    ::std::cosh;
26       
27    using    ::std::numeric_limits;
28   
29    using    ::boost::math::asinh;
30   
31   
32    static T const    epsilon = numeric_limits<float>::epsilon();
33   
34    T                y = sinh(x);
35    T                z = asinh(y);
36   
37    T                absolute_error = abs(z-x);
38    T                relative_error = absolute_error*cosh(x);
39    T                scaled_error = relative_error/epsilon;
40   
41    return(scaled_error);
42}
43
44
45BOOST_TEST_CASE_TEMPLATE_FUNCTION(asinh_test, T)
46{
47    BOOST_MESSAGE("Testing asinh in the real domain for "
48        << string_type_name<T>::_() << ".");
49   
50    for    (int i = 0; i <= 100; i++)
51    {
52        T    x = static_cast<T>(i-50)/static_cast<T>(5);
53       
54        BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
55            (asinh_error_evaluator(x))
56            (static_cast<T>(4)));
57    }
58}
59
60
61void    asinh_manual_check()
62{
63    BOOST_MESSAGE(" ");
64    BOOST_MESSAGE("asinh");
65   
66    for    (int i = 0; i <= 100; i++)
67    {
68        float        xf = static_cast<float>(i-50)/static_cast<float>(5);
69        double       xd = static_cast<double>(i-50)/static_cast<double>(5);
70        long double  xl =
71                static_cast<long double>(i-50)/static_cast<long double>(5);
72       
73        BOOST_MESSAGE(  ::std::setw(15)
74                     << asinh_error_evaluator(xf)
75                     << ::std::setw(15)
76                     << asinh_error_evaluator(xd)
77                     << ::std::setw(15)
78                     << asinh_error_evaluator(xl));
79    }
80   
81    BOOST_MESSAGE(" ");
82}
83
Note: See TracBrowser for help on using the repository browser.