From 18cb92bcde025abe9d39ad10cc1e442908289dc9 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sun, 24 Oct 2021 19:10:36 +0100 Subject: [PATCH 1/3] Update limits used in erf/erfc approximations. Fixes https://github.com/boostorg/math/issues/710. --- include/boost/math/special_functions/erf.hpp | 4 +- test/Jamfile.v2 | 1 + test/erf_limits_test.cpp | 73 ++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 test/erf_limits_test.cpp diff --git a/include/boost/math/special_functions/erf.hpp b/include/boost/math/special_functions/erf.hpp index 1f1071fc4d..69c6bd22d0 100644 --- a/include/boost/math/special_functions/erf.hpp +++ b/include/boost/math/special_functions/erf.hpp @@ -260,7 +260,7 @@ T erf_imp(T z, bool invert, const Policy& pol, const std::integral_constant +#include +#include + +#include + +BOOST_AUTO_TEST_CASE(limits_53_digits) +{ + double arg = 5.93f; + + double t = (double)boost::math::erf(boost::multiprecision::cpp_bin_float_50(arg)); + BOOST_CHECK_EQUAL(t, 1.0); + + arg = 5.9; + BOOST_CHECK_LT(boost::math::erf(arg), 1.0); + + arg = 28; + t = (double)boost::math::erfc(boost::multiprecision::cpp_bin_float_50(arg)); + BOOST_CHECK_EQUAL(t, 0.0); + + arg = 27.2; + + BOOST_CHECK_GT(boost::math::erfc(arg), 0.0); +} + +BOOST_AUTO_TEST_CASE(limits_64_digits) +{ + float arg = 6.6f; + + 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)); + BOOST_CHECK_EQUAL(t, 1.0); + +#if (LDBL_MANT_DIG == 64) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) + arg = 6.5; + BOOST_CHECK_LT(boost::math::erf(static_cast(arg)), 1.0L); +#endif + arg = 110; + t = (boost::multiprecision::cpp_bin_float_double_extended)boost::math::erfc(boost::multiprecision::cpp_bin_float_50(arg)); + BOOST_CHECK_EQUAL(t, 0.0); + +#if (LDBL_MANT_DIG == 64) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) + arg = 106.5; + BOOST_CHECK_GT(boost::math::erfc(static_cast(arg)), 0.0L); +#endif +} + +BOOST_AUTO_TEST_CASE(limits_113_digits) +{ + // + // This limit is not actually used in the code, logged here for future reference... + // + float arg = 8.8f; + + boost::multiprecision::cpp_bin_float_quad t = (boost::multiprecision::cpp_bin_float_quad)boost::math::erf(boost::multiprecision::cpp_bin_float_50(arg)); + BOOST_CHECK_EQUAL(t, 1.0); + + arg = 110; + t = (boost::multiprecision::cpp_bin_float_quad)boost::math::erfc(boost::multiprecision::cpp_bin_float_50(arg)); + BOOST_CHECK_EQUAL(t, 0.0); +} From d8078c71a34214de536433d3edaedb7684760e26 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Mon, 1 Nov 2021 18:32:07 +0000 Subject: [PATCH 2/3] Fix copyright declaration. --- test/erf_limits_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/erf_limits_test.cpp b/test/erf_limits_test.cpp index a7adda5c7c..3fc599fd8a 100644 --- a/test/erf_limits_test.cpp +++ b/test/erf_limits_test.cpp @@ -1,4 +1,4 @@ -// (C) Copyright John Maddock 2021. +// Copyright John Maddock 2021. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) From 08ff95dd148d3daf7a8f7855c5156460cf3ea07c Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Mon, 1 Nov 2021 19:24:31 +0000 Subject: [PATCH 3/3] Convert file to ASCII. --- test/erf_limits_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/erf_limits_test.cpp b/test/erf_limits_test.cpp index 3fc599fd8a..cf05bbd7a9 100644 --- a/test/erf_limits_test.cpp +++ b/test/erf_limits_test.cpp @@ -1,4 +1,4 @@ -// Copyright John Maddock 2021. +// (C) Copyright John Maddock 2021. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)