diff mbox series

[bug#56558] build: Simpler percentage calculation.

Message ID 20220714145851.20305-1-raingloom@riseup.net
State Accepted
Headers show
Series [bug#56558] build: Simpler percentage calculation. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Csepp July 14, 2022, 2:58 p.m. UTC
* build-aux/compile-all (%): Simpler calculation that avoids intermediate float.
---
 build-aux/compile-all.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Liliana Marie Prikler July 15, 2022, 8:22 a.m. UTC | #1
Am Donnerstag, dem 14.07.2022 um 16:58 +0200 schrieb raingloom:
> * build-aux/compile-all (%): Simpler calculation that avoids
> intermediate float.
> ---
>  build-aux/compile-all.scm | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/build-aux/compile-all.scm b/build-aux/compile-all.scm
> index 9ffbce43ad..6fdbe0dea8 100644
> --- a/build-aux/compile-all.scm
> +++ b/build-aux/compile-all.scm
> @@ -89,7 +89,7 @@ (define (parallel-job-count*)
>  
>  (define (% completed total)
>    "Return the completion percentage of COMPLETED over TOTAL as an
> integer."
> -  (inexact->exact (round (* 100. (/ completed total)))))
> +  (quotient (* 100 completed) total))
I am fairly certain that this changes the semantics of %.  Try for
example (% 23 24).

Cheers
Csepp July 15, 2022, 10:17 a.m. UTC | #2
Liliana Marie Prikler <liliana.prikler@ist.tugraz.at> writes:

> Am Donnerstag, dem 14.07.2022 um 16:58 +0200 schrieb raingloom:
>> * build-aux/compile-all (%): Simpler calculation that avoids
>> intermediate float.
>> ---
>>  build-aux/compile-all.scm | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/build-aux/compile-all.scm b/build-aux/compile-all.scm
>> index 9ffbce43ad..6fdbe0dea8 100644
>> --- a/build-aux/compile-all.scm
>> +++ b/build-aux/compile-all.scm
>> @@ -89,7 +89,7 @@ (define (parallel-job-count*)
>>  
>>  (define (% completed total)
>>    "Return the completion percentage of COMPLETED over TOTAL as an
>> integer."
>> -  (inexact->exact (round (* 100. (/ completed total)))))
>> +  (quotient (* 100 completed) total))
> I am fairly certain that this changes the semantics of %.  Try for
> example (% 23 24).
>
> Cheers

It rounds down instead of up, which, :shrug:.
If that's a deal breaker, feel free to close this.
Liliana Marie Prikler July 15, 2022, 10:27 a.m. UTC | #3
Am Freitag, dem 15.07.2022 um 12:17 +0200 schrieb Csepp:
> 
> Liliana Marie Prikler <liliana.prikler@ist.tugraz.at> writes:
> 
> > Am Donnerstag, dem 14.07.2022 um 16:58 +0200 schrieb raingloom:
> > > * build-aux/compile-all (%): Simpler calculation that avoids
> > > intermediate float.
> > > ---
> > >  build-aux/compile-all.scm | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/build-aux/compile-all.scm b/build-aux/compile-
> > > all.scm
> > > index 9ffbce43ad..6fdbe0dea8 100644
> > > --- a/build-aux/compile-all.scm
> > > +++ b/build-aux/compile-all.scm
> > > @@ -89,7 +89,7 @@ (define (parallel-job-count*)
> > >  
> > >  (define (% completed total)
> > >    "Return the completion percentage of COMPLETED over TOTAL as
> > > an
> > > integer."
> > > -  (inexact->exact (round (* 100. (/ completed total)))))
> > > +  (quotient (* 100 completed) total))
> > I am fairly certain that this changes the semantics of %.  Try for
> > example (% 23 24).
> > 
> > Cheers
> 
> It rounds down instead of up, which, :shrug:.
> If that's a deal breaker, feel free to close this.
It's not simply "rounding up", you need to round towards the nearest,
which can be done with just quotient and remainder, but is probably
more complicated than the float solution.
Csepp July 16, 2022, 10:04 p.m. UTC | #4
Liliana Marie Prikler <liliana.prikler@ist.tugraz.at> writes:

> Am Freitag, dem 15.07.2022 um 12:17 +0200 schrieb Csepp:
>> 
>> Liliana Marie Prikler <liliana.prikler@ist.tugraz.at> writes:
>> 
>> > Am Donnerstag, dem 14.07.2022 um 16:58 +0200 schrieb raingloom:
>> > > * build-aux/compile-all (%): Simpler calculation that avoids
>> > > intermediate float.
>> > > ---
>> > >  build-aux/compile-all.scm | 2 +-
>> > >  1 file changed, 1 insertion(+), 1 deletion(-)
>> > > 
>> > > diff --git a/build-aux/compile-all.scm b/build-aux/compile-
>> > > all.scm
>> > > index 9ffbce43ad..6fdbe0dea8 100644
>> > > --- a/build-aux/compile-all.scm
>> > > +++ b/build-aux/compile-all.scm
>> > > @@ -89,7 +89,7 @@ (define (parallel-job-count*)
>> > >  
>> > >  (define (% completed total)
>> > >    "Return the completion percentage of COMPLETED over TOTAL as
>> > > an
>> > > integer."
>> > > -  (inexact->exact (round (* 100. (/ completed total)))))
>> > > +  (quotient (* 100 completed) total))
>> > I am fairly certain that this changes the semantics of %.  Try for
>> > example (% 23 24).
>> > 
>> > Cheers
>> 
>> It rounds down instead of up, which, :shrug:.
>> If that's a deal breaker, feel free to close this.
> It's not simply "rounding up", you need to round towards the nearest,
> which can be done with just quotient and remainder, but is probably
> more complicated than the float solution.

Yeah, I meant it rounds up in that case. Since it's only used for
indicating progress to the user, being off by 1% is not something I'd
worry about, but whatevs, I guess we can leave it as is.
diff mbox series

Patch

diff --git a/build-aux/compile-all.scm b/build-aux/compile-all.scm
index 9ffbce43ad..6fdbe0dea8 100644
--- a/build-aux/compile-all.scm
+++ b/build-aux/compile-all.scm
@@ -89,7 +89,7 @@  (define (parallel-job-count*)
 
 (define (% completed total)
   "Return the completion percentage of COMPLETED over TOTAL as an integer."
-  (inexact->exact (round (* 100. (/ completed total)))))
+  (quotient (* 100 completed) total))
 
 ;; Install a SIGINT handler to give unwind handlers in 'compile-file' an
 ;; opportunity to run upon SIGINT and to remove temporary output files.