From 7b05d7a1a0cef4167e466dee591d683379b043ea Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Thu, 29 Dec 2022 13:49:13 -0500 Subject: [PATCH 1/3] Update Boost to 1.81 I will be the first to say it; I did in fact contribute to this release of Boost. However, it fixes a platitude of issues as this is a bugfix release. Therefore, I think updating to 1.81 is worth it. --- boost-math | 2 +- docs/cgmanifest.json | 2 +- tests/std/tests/LWG3234_math_special_overloads/test.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/boost-math b/boost-math index db2a7cbb44a..f395de082ec 160000 --- a/boost-math +++ b/boost-math @@ -1 +1 @@ -Subproject commit db2a7cbb44a84c4c9cba62232c07f18b22bd965d +Subproject commit f395de082eca6ee993a15f2bdb90277eda518295 diff --git a/docs/cgmanifest.json b/docs/cgmanifest.json index 81d35d6dd53..a7d932b2729 100644 --- a/docs/cgmanifest.json +++ b/docs/cgmanifest.json @@ -6,7 +6,7 @@ "type": "git", "git": { "repositoryUrl": "https://github.com/boostorg/math", - "commitHash": "db2a7cbb44a84c4c9cba62232c07f18b22bd965d" + "commitHash": "f395de082eca6ee993a15f2bdb90277eda518295" } } }, diff --git a/tests/std/tests/LWG3234_math_special_overloads/test.cpp b/tests/std/tests/LWG3234_math_special_overloads/test.cpp index 8975a1e2a2f..1654c10bc6d 100644 --- a/tests/std/tests/LWG3234_math_special_overloads/test.cpp +++ b/tests/std/tests/LWG3234_math_special_overloads/test.cpp @@ -197,7 +197,7 @@ void test_comp_ellint_2() { static_assert(is_same_v); static_assert(is_same_v); static_assert(is_same_v); - assert(comp_ellint_2(0) == acos(-1.0) / 2); + assert(expect_epsilons(comp_ellint_2(0), acos(-1.0) / 2, 2)); } void test_comp_ellint_3() { From 981619b40363ddde89e13258ef9498d65e7c2b89 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Thu, 5 Jan 2023 15:07:31 -0800 Subject: [PATCH 2/3] switch to isclose --- .../LWG3234_math_special_overloads/test.cpp | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/std/tests/LWG3234_math_special_overloads/test.cpp b/tests/std/tests/LWG3234_math_special_overloads/test.cpp index 1654c10bc6d..0f1e5b1c2a8 100644 --- a/tests/std/tests/LWG3234_math_special_overloads/test.cpp +++ b/tests/std/tests/LWG3234_math_special_overloads/test.cpp @@ -102,8 +102,24 @@ Ambiguous sph_neumann(unsigned int, Ambiguous) { return Ambiguous{}; } -bool expect_epsilons(double expected, double calculated, unsigned int multiple) { - return abs((calculated - expected) / expected) <= multiple * numeric_limits::epsilon(); +template +bool isclose(Float f, Float g, const int ulps = 1) { + if (f == g) { + return true; + } + + if (f > g) { + swap(f, g); + } + // f < g + for (int i = 0; i < ulps; ++i) { + f = nextafter(f, numeric_limits::infinity()); + if (f == g) { + return true; + } + } + + return false; } void test_assoc_laguerre() { @@ -197,7 +213,7 @@ void test_comp_ellint_2() { static_assert(is_same_v); static_assert(is_same_v); static_assert(is_same_v); - assert(expect_epsilons(comp_ellint_2(0), acos(-1.0) / 2, 2)); + assert(isclose(comp_ellint_2(0), acos(-1.0) / 2)); } void test_comp_ellint_3() { @@ -285,7 +301,7 @@ void test_cyl_bessel_k() { static_assert(is_same_v); static_assert(is_same_v); static_assert(is_same_v); - assert(expect_epsilons(cyl_bessel_k(0.5, 1), acos(-1.0) / 2 * (cyl_bessel_i(-0.5, 1) - cyl_bessel_i(0.5, 1)), 10)); + assert(isclose(cyl_bessel_k(0.5, 1), acos(-1.0) / 2 * (cyl_bessel_i(-0.5, 1) - cyl_bessel_i(0.5, 1)), 15)); } void test_cyl_neumann() { @@ -507,7 +523,7 @@ void test_sph_bessel() { static_assert(is_same_v); static_assert(is_same_v); static_assert(is_same_v); - assert(expect_epsilons(sph_bessel(1, 2), sin(2) / (static_cast(2) * 2) - cos(2) / 2, 2)); + assert(isclose(sph_bessel(1, 2), sin(2) / (2.0 * 2) - cos(2) / 2, 2)); } void test_sph_legendre() { @@ -527,7 +543,7 @@ void test_sph_legendre() { static_assert(is_same_v); const double pi = acos(-1.0); - assert(expect_epsilons(sph_legendre(3, 0, 1), 0.25 * sqrt(7 / pi) * (5 * pow(cos(1), 3) - 3 * cos(1)), 2)); + assert(isclose(sph_legendre(3, 0, 1), 0.25 * sqrt(7 / pi) * (5 * pow(cos(1), 3) - 3 * cos(1)))); } void test_sph_neumann() { @@ -545,7 +561,7 @@ void test_sph_neumann() { static_assert(is_same_v); static_assert(is_same_v); static_assert(is_same_v); - assert(expect_epsilons(sph_neumann(1, 1), -cos(1) - sin(1), 2)); + assert(isclose(sph_neumann(1, 1), -cos(1) - sin(1), 2)); } int main() { From fbc08d5741e3a1ffb968508e22cf53a3fd3aa767 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Fri, 6 Jan 2023 10:47:08 -0800 Subject: [PATCH 3/3] include utility for swap --- tests/std/tests/LWG3234_math_special_overloads/test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/std/tests/LWG3234_math_special_overloads/test.cpp b/tests/std/tests/LWG3234_math_special_overloads/test.cpp index 0f1e5b1c2a8..8594c3cf11e 100644 --- a/tests/std/tests/LWG3234_math_special_overloads/test.cpp +++ b/tests/std/tests/LWG3234_math_special_overloads/test.cpp @@ -5,6 +5,7 @@ #include #include #include +#include using namespace std;