Re: [PATCH v12 02/11] lib: kstrtox: add kstrtoudec64() and kstrtodec64()

From: David Laight

Date: Wed May 13 2026 - 06:13:05 EST


On Wed, 13 May 2026 08:14:28 +0100
Rodrigo Alencar <455.rodrigo.alencar@xxxxxxxxx> wrote:

> On 26/05/12 11:16PM, Andy Shevchenko wrote:
> > On Tue, May 12, 2026 at 08:39:21PM +0100, Rodrigo Alencar wrote:
...
> > Oh, I only now realised that this is sliding window for a single 64-bit signed value!
> > I was under impression that you wanted implementation that covers 128-bit signed value
> > (with 64 + 64)...
>
> So that was the initial approach with strntoull() with integer and fractional parts
> combined in iio core. At that time I realized that we ended up combining them anyways
> with:
>
> val64 = (u64)val * MICRO + val2
>
> so why not have val64 already! And all this made me realise that once leading 0s are ok,
> scale can be even bigger, e.g.
>
> scale = 20
> max = 0.09223372036854775807, min = -0.09223372036854775808
> scale = 21
> max = 0.009223372036854775807, min = -0.009223372036854775808
>
> It might be a sliding window of 19 digits, but here we trade range for scale, precision
> is still fixed at 64-bit.

I wouldn't worry about that case unless it 'falls out in the wash'.

> I have a new idea to make thing simpler, actually
> it would go back to what David pointed out in the past.

:-)

-- David

> Let me put this together...
>
> > > I am not representing -0.9999999999999999999 as is. The desired scale will have this
> > > truncated. It may be -0.9999 or -0.999999 or -0.9. And this is practical for a
> > > reasonable scale value... for pico and femto precision you still get a decent range.
> >
> > --
> > With Best Regards,
> > Andy Shevchenko
> >
> >
>