# HG changeset patch # User Rubidium # Date 2024-01-20 14:59:53 # Node ID cdd8c63fd245c23a917f428b557ef3edae118a12 # Parent a0987065cc7d6dc72d8f88acce5f130cc6fcbcfe Remove: LeastCommonMultiple / GreatestCommonDivisor Use std::lcm / std::gcd instead. diff --git a/src/core/math_func.cpp b/src/core/math_func.cpp --- a/src/core/math_func.cpp +++ b/src/core/math_func.cpp @@ -13,41 +13,6 @@ #include "../safeguards.h" /** - * Compute least common multiple (lcm) of arguments \a a and \a b, the smallest - * integer value that is a multiple of both \a a and \a b. - * @param a First number. - * @param b second number. - * @return Least common multiple of values \a a and \a b. - * - * @note This function only works for non-negative values of \a a and \a b. - */ -int LeastCommonMultiple(int a, int b) -{ - if (a == 0 || b == 0) return 0; // By definition. - if (a == 1 || a == b) return b; - if (b == 1) return a; - - return a * b / GreatestCommonDivisor(a, b); -} - -/** - * Compute greatest common divisor (gcd) of \a a and \a b. - * @param a First number. - * @param b second number. - * @return Greatest common divisor of \a a and \a b. - */ -int GreatestCommonDivisor(int a, int b) -{ - while (b != 0) { - int t = b; - b = a % b; - a = t; - } - return a; - -} - -/** * Deterministic approximate division. * Cancels out division errors stemming from the integer nature of the division over multiple runs. * @param a Dividend. diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -309,8 +309,6 @@ inline uint ToPercent16(uint i) return i * 101 >> 16; } -int LeastCommonMultiple(int a, int b); -int GreatestCommonDivisor(int a, int b); int DivideApprox(int a, int b); /** diff --git a/src/tests/math_func.cpp b/src/tests/math_func.cpp --- a/src/tests/math_func.cpp +++ b/src/tests/math_func.cpp @@ -13,41 +13,6 @@ #include "../core/math_func.hpp" -TEST_CASE("LeastCommonMultipleTest - Zero") -{ - CHECK(0 == LeastCommonMultiple(0, 0)); - CHECK(0 == LeastCommonMultiple(0, 600)); - CHECK(0 == LeastCommonMultiple(600, 0)); -} - -TEST_CASE("LeastCommonMultipleTest - FindLCM") -{ - CHECK(25 == LeastCommonMultiple(5, 25)); - CHECK(25 == LeastCommonMultiple(25, 5)); - CHECK(130 == LeastCommonMultiple(5, 26)); - CHECK(130 == LeastCommonMultiple(26, 5)); -} - -TEST_CASE("GreatestCommonDivisorTest - Negative") -{ - CHECK(4 == GreatestCommonDivisor(4, -52)); - // CHECK(3 == GreatestCommonDivisor(-27, 6)); // error - returns -3 -} - -TEST_CASE("GreatestCommonDivisorTest - Zero") -{ - CHECK(27 == GreatestCommonDivisor(0, 27)); - CHECK(27 == GreatestCommonDivisor(27, 0)); -} - -TEST_CASE("GreatestCommonDivisorTest - FindGCD") -{ - CHECK(5 == GreatestCommonDivisor(5, 25)); - CHECK(5 == GreatestCommonDivisor(25, 5)); - CHECK(1 == GreatestCommonDivisor(7, 27)); - CHECK(1 == GreatestCommonDivisor(27, 7)); -} - TEST_CASE("DivideApproxTest - Negative") { CHECK(-2 == DivideApprox(-5, 2));