| 1 | // unit test file acosh.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/acosh.hpp> |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | #include <boost/test/unit_test.hpp> |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | template<typename T> |
|---|
| 21 | T acosh_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::acosh; |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | static T const epsilon = numeric_limits<float>::epsilon(); |
|---|
| 33 | |
|---|
| 34 | T y = cosh(x); |
|---|
| 35 | T z = acosh(y); |
|---|
| 36 | |
|---|
| 37 | T absolute_error = abs(z-abs(x)); |
|---|
| 38 | T relative_error = absolute_error*abs(sinh(x)); |
|---|
| 39 | T scaled_error = relative_error/epsilon; |
|---|
| 40 | |
|---|
| 41 | return(scaled_error); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | BOOST_TEST_CASE_TEMPLATE_FUNCTION(acosh_test, T) |
|---|
| 46 | { |
|---|
| 47 | BOOST_MESSAGE("Testing acosh 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 | (acosh_error_evaluator(x)) |
|---|
| 56 | (static_cast<T>(4))); |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | void acosh_manual_check() |
|---|
| 62 | { |
|---|
| 63 | BOOST_MESSAGE(" "); |
|---|
| 64 | BOOST_MESSAGE("acosh"); |
|---|
| 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 | << acosh_error_evaluator(xf) |
|---|
| 75 | << ::std::setw(15) |
|---|
| 76 | << acosh_error_evaluator(xd) |
|---|
| 77 | << ::std::setw(15) |
|---|
| 78 | << acosh_error_evaluator(xl)); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | BOOST_MESSAGE(" "); |
|---|
| 82 | } |
|---|
| 83 | |
|---|