- return human_readable_inexact (n, buf, from_block_size, output_block_size,
- human_round_to_even);
+ register char *d;
+ size_t grouplen = SIZE_MAX;
+ size_t thousands_seplen = strlen (thousands_sep);
+ size_t i = numberlen;
+
+ /* The maximum possible value for NUMBERLEN is the number of digits
+ in the square of the largest uintmax_t, so double the size of
+ uintmax_t before converting to a bound. 302 / 1000 is ceil
+ (log10 (2.0)). Add 1 for integer division truncation. */
+ char buf[2 * sizeof (uintmax_t) * CHAR_BIT * 302 / 1000 + 1];
+
+ memcpy (buf, number, numberlen);
+ d = number + numberlen;
+
+ for (;;)
+ {
+ unsigned char g = *grouping;
+
+ if (g)
+ {
+ grouplen = g < CHAR_MAX ? g : i;
+ grouping++;
+ }
+
+ if (i < grouplen)
+ grouplen = i;
+
+ d -= grouplen;
+ i -= grouplen;
+ memcpy (d, buf + i, grouplen);
+ if (i == 0)
+ return d;
+
+ d -= thousands_seplen;
+ memcpy (d, thousands_sep, thousands_seplen);
+ }