NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/59811: strpct round-off error



The following reply was made to PR lib/59811; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: lib/59811: strpct round-off error
Date: Tue, 02 Dec 2025 07:33:44 +0700

     Date:        Sun, 30 Nov 2025 21:10:00 +0000 (UTC)
     From:        jlduran%gmail.com@localhost
     Message-ID:  <20251130211000.A4F7E1A923C%mollari.NetBSD.org@localhost>
 
 
   | While porting df tests to FreeBSD, I realized some percentages
   | were incorrectly rounded.
 
 Hmm.   If I do the same calculation in bc (whose manual does say that
 it truncates the results from divide operations) I see the same thing:
 
 scale=1
 1443260007 * 100 / 2164890010
 66.6
 scale=20
 1443260007 * 100 / 2164890010
 66.66666668206390771787
 
 I'm not certain that having df give answers different than what bc
 would give were the user to use that to calculate the values, is
 necessarily a good idea.
 
   | Apparently, it has issues rounding 66.6666... to 66.7 or 67.
 
 ["it" being strpct(3) of course]
 
 That, or it simply implements "round towards 0" for all operations.
 
 I will allow others to ponder a little upon what result we should be
 producing here (in the grand scheme of things I doubt it matters a lot)
 while I take a look to see how strpct() might be adapted to do "rounding
 to nearest" which is what I assume you're expecting it to do.
 
 Maybe we need variants of str[s]pct() with a flags arg to indicate which
 kind of rounding is desired, or would that be way over the top?
 
 kre
 


Home | Main Index | Thread Index | Old Index