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 #define BOOST_TEST_MAiN 14 #include <boost/math/special_functions/asinh.hpp> 15 16 17 #include <boost/test/unit_test.hpp> 18 19 20 template<typename T> asinh_error_evaluator(T x)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 BOOST_TEST_CASE_TEMPLATE_FUNCTION(asinh_test,T)45BOOST_TEST_CASE_TEMPLATE_FUNCTION(asinh_test, T) 46 { 47 BOOST_TEST_MESSAGE("Testing asinh in the real domain for " 48 << string_type_name<T>::_() << "."); 49 50 for (int i = 0; i <= 80; i++) 51 { 52 T x = static_cast<T>(i-40)/static_cast<T>(4); 53 54 BOOST_CHECK_PREDICATE(::std::less_equal<T>(), 55 (asinh_error_evaluator(x)) 56 (static_cast<T>(4))); 57 } 58 // 59 // Special cases: 60 // 61 if(std::numeric_limits<T>::has_infinity) 62 { 63 T inf = std::numeric_limits<T>::infinity(); 64 boost::math::policies::policy<boost::math::policies::overflow_error<boost::math::policies::ignore_error> > pol; 65 BOOST_CHECK_EQUAL(boost::math::asinh(inf, pol), inf); 66 BOOST_CHECK_EQUAL(boost::math::asinh(-inf, pol), -inf); 67 } 68 } 69 70 asinh_manual_check()71void asinh_manual_check() 72 { 73 BOOST_TEST_MESSAGE(" "); 74 BOOST_TEST_MESSAGE("asinh"); 75 76 for (int i = 0; i <= 80; i++) 77 { 78 float xf = static_cast<float>(i-40)/static_cast<float>(4); 79 double xd = static_cast<double>(i-40)/static_cast<double>(4); 80 long double xl = 81 static_cast<long double>(i-40)/static_cast<long double>(4); 82 83 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS 84 BOOST_TEST_MESSAGE( ::std::setw(15) 85 << asinh_error_evaluator(xf) 86 << ::std::setw(15) 87 << asinh_error_evaluator(xd) 88 << ::std::setw(15) 89 << asinh_error_evaluator(xl)); 90 #else 91 BOOST_TEST_MESSAGE( ::std::setw(15) 92 << asinh_error_evaluator(xf) 93 << ::std::setw(15) 94 << asinh_error_evaluator(xd)); 95 #endif 96 } 97 98 BOOST_TEST_MESSAGE(" "); 99 } 100 101