Re: [PATCH v5 1/7] lib: kstrtox: support E notation in kstrtoudec64() and kstrtodec64()

From: Andy Shevchenko

Date: Tue Nov 03 2026 - 13:19:30 EST


On Mon, Nov 02, 2026 at 07:40:59AM -0300, Rodrigo Alencar via B4 Relay wrote:
>
> Allow decimal strings to carry an exponent suffix, such as "2.7e10" or
> "271828e-5", in kstrtoudec64() and kstrtodec64(). The exponent is added
> to the requested scale to work out how many integer and fractional digits
> are consumed. A negative effective exponent drops integer digits.
>
> The digits are now scanned first and the string termination is checked
> before any conversion. A missing or malformed exponent ("1e", "1e+")
> returns -EINVAL. An exponent that overflows when added to the scale, or
> that makes the result exceed 64 bits, returns -ERANGE.

...

> +static int skip_digits(const char **s)

In case we need a new version, the skip_and_count_digits() fits better.

> +{
> + const char *start = *s;
> +
> + while (isdigit(**s))
> + (*s)++;
> +
> + return *s - start;
> +}

--
With Best Regards,
Andy Shevchenko