From 0f80c1010468b4a112293b62c684b9f70baf6159 Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Sat, 19 Mar 2022 16:58:43 +0000 Subject: [PATCH] Try "gentler" test case I verified that we hit GCC 10's constexpr limit with `wheel_factorizer<1>`, but pass with `wheel_factorizer<4>`. I hope this number is enough smaller than the square root of the previous value that the other compilers will be able to handle it. If not: we'll go lower. --- test/unit_test/runtime/magnitude_test.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/unit_test/runtime/magnitude_test.cpp b/test/unit_test/runtime/magnitude_test.cpp index c3138fb8..9958c715 100644 --- a/test/unit_test/runtime/magnitude_test.cpp +++ b/test/unit_test/runtime/magnitude_test.cpp @@ -156,15 +156,18 @@ TEST_CASE("make_ratio performs prime factorization correctly") as_magnitude(); } - SECTION ("Can handle prime number which would exceed GCC iteration limit") { + SECTION("Can handle prime number which would exceed GCC iteration limit") + { // GCC 10 has a constexpr loop iteration limit of 262144. A naive algorithm, which performs trial division on 2 and // all odd numbers up to sqrt(N), will exceed this limit for the following prime. Thus, for this test to pass, we // need to be using a more efficient algorithm. (We could increase the limit, but we don't want users to have to // mess with compiler flags just to compile the code.) - as_magnitude<334'524'384'739>(); + constexpr std::intmax_t big_prime = 414'131; + as_magnitude(); } - SECTION ("Can bypass computing primes by providing known_first_factor") { + SECTION("Can bypass computing primes by providing known_first_factor") + { // Sometimes, even wheel factorization isn't enough to handle the compilers' limits on constexpr steps and/or // iterations. To work around these cases, we can explicitly provide the correct answer directly to the compiler. // @@ -383,7 +386,7 @@ TEST_CASE("int_power computes integer powers") TEST_CASE("Prime helper functions") { - SECTION ("multiplicity") + SECTION("multiplicity") { CHECK(multiplicity(2, 8) == 3); CHECK(multiplicity(2, 1024) == 10);