lib/60635: humanize_number(3): exa/exbi issues

"[email protected] via gnats" <[email protected]>
Newsgroups gmane.os.netbsd.bugs
Message-ID <[email protected]>
>Number:         60635
>Category:       lib
>Synopsis:       humanize_number(3): exa/exbi issues
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 23 16:40:01 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current, 11, 10, 9, ...
>Organization:
The NetBSD Countation, SInc.
>Environment:
>Description:

	1. humanize_number() doesn't have any options for producing IEC
	   byte units like KiB/GiB and always uses the nonstandard
	   binary `SI' prefixes (or JEDEC units).

	   Even if you find pronouncing kitty-kibble-bytes^Wkibibytes
	   goofy, we should have a way to produce the IEC units,
	   especially in contexts where binary vs decimal is not clear
	   (like packet rates, which are often in measured in
	   decimal-powers of bits or packets per second, while traffic
	   is often measured in binary-powers of bytes per second).

	2. humanize_number() apparently can't handle single-digit
	   numbers of EiB.

>How-To-Repeat:
$ cat h.c
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>

static void
show(int64_t x)
{
	char buf[5] = "";
	int result;

	result = humanize_number(buf, sizeof(buf), x, "", HN_AUTOSCALE, 0);
	printf("%"PRId64": [%d] -> \"%s\"\n", x, result, buf);
}

int
main(void)
{

	show(1);
	show(1024LL*1024);
	show(1024LL*1024*1024);
	show(1024LL*1024*1024*1024);
	show(1024LL*1024*1024*1024*1024);
	show(1024LL*1024*1024*1024*1024*1024);
	fflush(stdout);
	return ferror(stdout);
}
$ make h
cc -O2   -o h h.c 
$ ./h
1: [2] -> "1 "
1048576: [3] -> "1 M"
1073741824: [3] -> "1 G"
1099511627776: [3] -> "1 T"
1125899906842624: [3] -> "1 P"
1152921504606846976: [-1] -> ""

	Expected output:

1: [2] -> "1 "
1048576: [3] -> "1 M"
1073741824: [3] -> "1 G"
1099511627776: [3] -> "1 T"
1125899906842624: [3] -> "1 P"
1152921504606846976: [3] -> "1 E"

>Fix:

	Yes, please!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.