diff --git a/src/core/include/units/bits/prime.h b/src/core/include/units/bits/prime.h index aaa20e4f..698f05bf 100644 --- a/src/core/include/units/bits/prime.h +++ b/src/core/include/units/bits/prime.h @@ -124,7 +124,7 @@ constexpr std::size_t product(const std::array& values) // // [1] https://en.wikipedia.org/wiki/Wheel_factorization template -struct WheelFactorizer { +struct wheel_factorizer { static constexpr auto basis = first_n_primes(); static constexpr std::size_t wheel_size = product(basis); static constexpr auto coprimes_in_first_wheel = diff --git a/src/core/include/units/magnitude.h b/src/core/include/units/magnitude.h index ffd86e7e..94140397 100644 --- a/src/core/include/units/magnitude.h +++ b/src/core/include/units/magnitude.h @@ -34,7 +34,7 @@ namespace units { namespace detail { // Higher numbers use fewer trial divisions, at the price of more storage space. -using Factorizer = WheelFactorizer<4>; +using factorizer = wheel_factorizer<4>; } // namespace detail /** @@ -274,7 +274,7 @@ constexpr std::intmax_t remove_power(std::intmax_t base, std::intmax_t pow, std: } // A way to check whether a number is prime at compile time. -constexpr bool is_prime(std::intmax_t n) { return (n >= 0) && Factorizer::is_prime(static_cast(n)); } +constexpr bool is_prime(std::intmax_t n) { return (n >= 0) && factorizer::is_prime(static_cast(n)); } constexpr bool is_valid_base_power(const BasePower auto& bp) { @@ -502,7 +502,7 @@ struct prime_factorization { if constexpr (known_first_factor.has_value()) { return known_first_factor.value(); } else { - return static_cast(Factorizer::find_first_factor(N)); + return static_cast(factorizer::find_first_factor(N)); } } diff --git a/test/unit_test/static/prime_test.cpp b/test/unit_test/static/prime_test.cpp index 9cb017b6..020a1fe7 100644 --- a/test/unit_test/static/prime_test.cpp +++ b/test/unit_test/static/prime_test.cpp @@ -31,7 +31,7 @@ namespace { template constexpr bool check_primes(std::index_sequence) { - return ((Is < 2 || WheelFactorizer::is_prime(Is) == is_prime_by_trial_division(Is)) && ...); + return ((Is < 2 || wheel_factorizer::is_prime(Is) == is_prime_by_trial_division(Is)) && ...); } static_assert(check_primes<2>(std::make_index_sequence<122>{})); @@ -44,33 +44,33 @@ static_assert(check_primes<2>(std::make_index_sequence<122>{})); // using numbers of the form (210 * n + 121) as trial divisors, which is a problem if any are prime. For n = 1, we have // a divisor of (210 + 121 = 331), which happens to be prime but will not be used. Thus, (331 * 331 = 109561) is a // composite number which could wrongly appear prime if we skip over 331. -static_assert(WheelFactorizer<4>::is_prime(109561) == is_prime_by_trial_division(109561)); +static_assert(wheel_factorizer<4>::is_prime(109561) == is_prime_by_trial_division(109561)); -static_assert(WheelFactorizer<1>::coprimes_in_first_wheel.size() == 1); -static_assert(WheelFactorizer<2>::coprimes_in_first_wheel.size() == 2); -static_assert(WheelFactorizer<3>::coprimes_in_first_wheel.size() == 8); -static_assert(WheelFactorizer<4>::coprimes_in_first_wheel.size() == 48); -static_assert(WheelFactorizer<5>::coprimes_in_first_wheel.size() == 480); +static_assert(wheel_factorizer<1>::coprimes_in_first_wheel.size() == 1); +static_assert(wheel_factorizer<2>::coprimes_in_first_wheel.size() == 2); +static_assert(wheel_factorizer<3>::coprimes_in_first_wheel.size() == 8); +static_assert(wheel_factorizer<4>::coprimes_in_first_wheel.size() == 48); +static_assert(wheel_factorizer<5>::coprimes_in_first_wheel.size() == 480); -static_assert(WheelFactorizer<3>::coprimes_in_first_wheel[0] == 1); -static_assert(WheelFactorizer<3>::coprimes_in_first_wheel[1] == 7); -static_assert(WheelFactorizer<3>::coprimes_in_first_wheel[2] == 11); -static_assert(WheelFactorizer<3>::coprimes_in_first_wheel[3] == 13); -static_assert(WheelFactorizer<3>::coprimes_in_first_wheel[4] == 17); -static_assert(WheelFactorizer<3>::coprimes_in_first_wheel[5] == 19); -static_assert(WheelFactorizer<3>::coprimes_in_first_wheel[6] == 23); -static_assert(WheelFactorizer<3>::coprimes_in_first_wheel[7] == 29); +static_assert(wheel_factorizer<3>::coprimes_in_first_wheel[0] == 1); +static_assert(wheel_factorizer<3>::coprimes_in_first_wheel[1] == 7); +static_assert(wheel_factorizer<3>::coprimes_in_first_wheel[2] == 11); +static_assert(wheel_factorizer<3>::coprimes_in_first_wheel[3] == 13); +static_assert(wheel_factorizer<3>::coprimes_in_first_wheel[4] == 17); +static_assert(wheel_factorizer<3>::coprimes_in_first_wheel[5] == 19); +static_assert(wheel_factorizer<3>::coprimes_in_first_wheel[6] == 23); +static_assert(wheel_factorizer<3>::coprimes_in_first_wheel[7] == 29); -static_assert(!WheelFactorizer<1>::is_prime(0)); -static_assert(!WheelFactorizer<1>::is_prime(1)); -static_assert(WheelFactorizer<1>::is_prime(2)); +static_assert(!wheel_factorizer<1>::is_prime(0)); +static_assert(!wheel_factorizer<1>::is_prime(1)); +static_assert(wheel_factorizer<1>::is_prime(2)); -static_assert(!WheelFactorizer<2>::is_prime(0)); -static_assert(!WheelFactorizer<2>::is_prime(1)); -static_assert(WheelFactorizer<2>::is_prime(2)); +static_assert(!wheel_factorizer<2>::is_prime(0)); +static_assert(!wheel_factorizer<2>::is_prime(1)); +static_assert(wheel_factorizer<2>::is_prime(2)); -static_assert(!WheelFactorizer<3>::is_prime(0)); -static_assert(!WheelFactorizer<3>::is_prime(1)); -static_assert(WheelFactorizer<3>::is_prime(2)); +static_assert(!wheel_factorizer<3>::is_prime(0)); +static_assert(!wheel_factorizer<3>::is_prime(1)); +static_assert(wheel_factorizer<3>::is_prime(2)); } // namespace