NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/59811: strpct round-off error
>Number: 59811
>Category: lib
>Synopsis: strpct round-off error
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Nov 30 21:10:00 +0000 2025
>Originator: Jose Luis Duran
>Release: trunk
>Organization:
FreeBSD
>Environment:
>Description:
While porting df tests to FreeBSD, I realized some percentages were incorrectly rounded.
The issue seems to be that df on NetBSD uses strspct(3) to compute the percentage. Apparently, it has issues rounding 66.6666... to 66.7 or 67.
With the mwe.c program below, we can replicate the issue.
>How-To-Repeat:
% cat mwe.c
#include <stdio.h>
#include <util.h>
int
main(void)
{
char pb[64];
strpct(pb, sizeof(pb), 1443260007, 2164890010, 1);
printf(" Current: %s\n", pb);
printf("Expected: 66.7\n");
return (0);
}
% cc -lutil mwe.c
% ./a.out
Current: 66.6
Expected: 66.7
>Fix:
Home |
Main Index |
Thread Index |
Old Index