fix(progress): Now calculating progress correctly
This commit is contained in:
parent
44c663c54f
commit
1514bdb3fe
11
main.go
11
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]
|
||||
|
Loading…
Reference in New Issue
Block a user