]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // (C) Copyright John Maddock 2021. |
2 | // Use, modification and distribution are subject to the | |
3 | // Boost Software License, Version 1.0. (See accompanying file | |
4 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | // | |
7 | // This test verifies that the limits we use in the numerical approximations to erf/erc | |
8 | // are indeed correct. The values tested must of course match the values used in erf.hpp. | |
9 | // See https://github.com/boostorg/math/issues/710 | |
10 | // | |
11 | ||
12 | #define BOOST_TEST_MODULE erf_limits | |
13 | ||
14 | #include <boost/multiprecision/cpp_bin_float.hpp> | |
15 | #include <boost/math/special_functions/erf.hpp> | |
16 | #include <boost/test/included/unit_test.hpp> | |
17 | ||
18 | #include <cfloat> | |
19 | ||
20 | BOOST_AUTO_TEST_CASE(limits_53_digits) | |
21 | { | |
22 | double arg = 5.93f; | |
23 | ||
24 | double t = (double)boost::math::erf(boost::multiprecision::cpp_bin_float_50(arg)); | |
25 | BOOST_CHECK_EQUAL(t, 1.0); | |
26 | ||
27 | arg = 5.9; | |
28 | BOOST_CHECK_LT(boost::math::erf(arg), 1.0); | |
29 | ||
30 | arg = 28; | |
31 | t = (double)boost::math::erfc(boost::multiprecision::cpp_bin_float_50(arg)); | |
32 | BOOST_CHECK_EQUAL(t, 0.0); | |
33 | ||
34 | arg = 27.2; | |
35 | ||
36 | BOOST_CHECK_GT(boost::math::erfc(arg), 0.0); | |
37 | } | |
38 | ||
39 | BOOST_AUTO_TEST_CASE(limits_64_digits) | |
40 | { | |
41 | float arg = 6.6f; | |
42 | ||
43 | boost::multiprecision::cpp_bin_float_double_extended t = (boost::multiprecision::cpp_bin_float_double_extended)boost::math::erf(boost::multiprecision::cpp_bin_float_50(arg)); | |
44 | BOOST_CHECK_EQUAL(t, 1.0); | |
45 | ||
46 | #if (LDBL_MANT_DIG == 64) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) | |
47 | arg = 6.5; | |
48 | BOOST_CHECK_LT(boost::math::erf(static_cast<long double>(arg)), 1.0L); | |
49 | #endif | |
50 | arg = 110; | |
51 | t = (boost::multiprecision::cpp_bin_float_double_extended)boost::math::erfc(boost::multiprecision::cpp_bin_float_50(arg)); | |
52 | BOOST_CHECK_EQUAL(t, 0.0); | |
53 | ||
54 | #if (LDBL_MANT_DIG == 64) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) | |
55 | arg = 106.5; | |
56 | BOOST_CHECK_GT(boost::math::erfc(static_cast<long double>(arg)), 0.0L); | |
57 | #endif | |
58 | } | |
59 | ||
60 | BOOST_AUTO_TEST_CASE(limits_113_digits) | |
61 | { | |
62 | // | |
63 | // This limit is not actually used in the code, logged here for future reference... | |
64 | // | |
65 | float arg = 8.8f; | |
66 | ||
67 | boost::multiprecision::cpp_bin_float_quad t = (boost::multiprecision::cpp_bin_float_quad)boost::math::erf(boost::multiprecision::cpp_bin_float_50(arg)); | |
68 | BOOST_CHECK_EQUAL(t, 1.0); | |
69 | ||
70 | arg = 110; | |
71 | t = (boost::multiprecision::cpp_bin_float_quad)boost::math::erfc(boost::multiprecision::cpp_bin_float_50(arg)); | |
72 | BOOST_CHECK_EQUAL(t, 0.0); | |
73 | } |