From c4d48e982a2cbfb767916afa6f08ea5b587c9b76 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Wed, 26 Feb 2025 15:13:45 +0100 Subject: [PATCH] Fix minor bug in progress calculation --- src/FactorizationController.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/FactorizationController.cpp b/src/FactorizationController.cpp index de4e1b8..fca7ce8 100644 --- a/src/FactorizationController.cpp +++ b/src/FactorizationController.cpp @@ -18,12 +18,14 @@ long long FactorizationController::curFactNumber() const { int FactorizationController::progress() const { // If the original number is set to 0, the computation wasn't yet initialized / was reset. - if (m_originalNumber == 0) + // If the current factor is at 2, the computation has just started, return early to avoid + // zero division issues. + if (m_originalNumber == 0 || m_currentFactor <= 2) return 0; - // If current factor is at or below 2 already, we must be done, - // stopFactor can never be less than 2, that makes no sense. - if (m_currentFactNumber == 1 || m_currentFactor <= 2 || m_currentFactor > m_stopFactor) + // If the current number being factorized is 1, we must be done, all factors were found + // Alternatively, we're also done when the current factor passes the stop factor. + if (m_currentFactNumber == 1 || m_currentFactor > m_stopFactor) return 100; // Determine the progress based on the current factor, in comparison to stop factor.