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)
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
12 #define BOOST_TEST_MODULE erf_limits
14 #include <boost/multiprecision/cpp_bin_float.hpp>
15 #include <boost/math/special_functions/erf.hpp>
16 #include <boost/test/included/unit_test.hpp>
20 BOOST_AUTO_TEST_CASE(limits_53_digits
)
24 double t
= (double)boost::math::erf(boost::multiprecision::cpp_bin_float_50(arg
));
25 BOOST_CHECK_EQUAL(t
, 1.0);
28 BOOST_CHECK_LT(boost::math::erf(arg
), 1.0);
31 t
= (double)boost::math::erfc(boost::multiprecision::cpp_bin_float_50(arg
));
32 BOOST_CHECK_EQUAL(t
, 0.0);
36 BOOST_CHECK_GT(boost::math::erfc(arg
), 0.0);
39 BOOST_AUTO_TEST_CASE(limits_64_digits
)
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);
46 #if (LDBL_MANT_DIG == 64) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
48 BOOST_CHECK_LT(boost::math::erf(static_cast<long double>(arg
)), 1.0L);
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);
54 #if (LDBL_MANT_DIG == 64) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
56 BOOST_CHECK_GT(boost::math::erfc(static_cast<long double>(arg
)), 0.0L);
60 BOOST_AUTO_TEST_CASE(limits_113_digits
)
63 // This limit is not actually used in the code, logged here for future reference...
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);
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);