Re: [PATCH v2 next] tools/nolibc: Optimise and common up the number to ascii functions
From: David Laight
Date: Tue Feb 17 2026 - 07:01:13 EST
On Mon, 16 Feb 2026 22:16:20 +0000
David Laight <david.laight.linux@xxxxxxxxx> wrote:
> On Mon, 16 Feb 2026 19:46:12 +0100
> Thomas Weißschuh <linux@xxxxxxxxxxxxxx> wrote:
>
> > On 2026-02-13 11:08:59+0000, David Laight wrote:
> > > On Sun, 8 Feb 2026 19:53:08 +0000
> > > david.laight.linux@xxxxxxxxx wrote:
> > >
> > > > From: David Laight <david.laight.linux@xxxxxxxxx>
> > > >
> > > > Implement u[64]to[ah]_r() using a common function that uses multiply
> > > > by reciprocal to generate the least significant digit first and then
> > > > reverses the string.
> > >
> > > Self-nak on this version :-(
> > >
> > > The division code can end up generating a negative remainder for
> > > very large values (probably only ones over 1<<63).
> >
> > Ok. Maybe some tests for these edgecases are in order, too.
> > Do you want to add them?
>
> The problem is I'm not sure how to decide where they are.
> The v1 patch is fine, it expects to get a large remainder and then
> fixes up the error.
I think I can convince myself that the error on the quotient is less
than 2 (and some of that 2 is the remainder that becomes the digit).
Which means the maximum remainder (for base 10) is less than 20.
So a simple:
if (digit >= base) {
digit -= base;
quotient++;
}
suffices (without s/if/while/).
David