From 1514bdb3fe791c89849df4e93abce78f218e65e3 Mon Sep 17 00:00:00 2001 From: datalore Date: Thu, 3 Oct 2024 13:20:25 +0200 Subject: [PATCH] fix(progress): Now calculating progress correctly --- main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index bcbe620..57e60e4 100644 --- a/main.go +++ b/main.go @@ -20,8 +20,8 @@ type Config struct { UseTxtWrite bool } -func calculateProgress(start, end, step, index int64) float32 { - steps := (end - start) / step +func calculateProgress(start, end, index int64) float32 { + steps := (end - start) current := index - start if current == 0 { return 0 @@ -103,9 +103,10 @@ func generatePrimesCPU(upperLimit int64, primes []int64, numRoutines int, progre fmt.Printf("Calculating with %d routines\n\n", numRoutines) - for i := (primes[len(primes) - 1] + 2); i <= upperLimit; i += 2 { + continueFrom := primes[len(primes) - 1] + 2 + for i := continueFrom; i <= upperLimit; i += 2 { select { - case progress <- calculateProgress(6, upperLimit, 1, i): + case progress <- calculateProgress(continueFrom, upperLimit, i): default: } @@ -147,7 +148,7 @@ func calculatePrimeParts(number int64, primes []int64) []int64 { for i := int64(len(primes) - 1); i >= 0; i-- { select { - case progress <- 1.0 - calculateProgress(0, int64(len(primes) - 1), 1, i): + case progress <- 1.0 - calculateProgress(0, int64(len(primes) - 1), i): default: } flooredDiv := number / primes[i]