Re: [PATCH RFC v3 0/5] Add E notation support to kstrtodec64() and IIO sysfs writes

From: Rodrigo Alencar

Date: Tue Oct 20 2026 - 08:55:10 EST


On 20/10/26 09:26, Rodrigo Alencar via B4 Relay wrote:
> This series lets kstrtoudec64() and kstrtodec64() accept numbers in E
> notation (scientific notation), such as "2.7e9", "1.5E-3" or "1e+16".
> It then moves the IIO core fixed-point parser over to kstrtodec64(), so
> every IIO channel attribute written through iio_write_channel_info()
> accepts that format as well.

...

> Digits beyond the resulting precision are now rounded to nearest, ties
> to even, instead of truncated (new patch 2). This follows from the
> second motivation: floating point values printed by userspace often end
> just below the intended decimal value. "%.17g" of 0.3 gives
> "0.29999999999999999", which truncation turns into 299999 at micro
> precision instead of 300000. E notation makes this more visible, since
> a negative exponent can drop integer digits: with truncation, "19e-1"
> written to an integer attribute gives 1. Round-half-even is the IEEE 754
> default, as used by strtod() and printf(), it is unbiased and symmetric
> for negative values, and inputs that fit the precision (including values
> read back from sysfs) are parsed exactly as before. The rounding is done
> before the IIO core conversion, so IIO fixed-point writes change
> behaviour only once.
>
> This changes existing kstrtodec64() behaviour, so feedback is welcome on
> whether it should stay in this series or be sent as a follow-up.

This might not sound good, but I have increased the scope of the series a bit.
I think it was a good fit and it would not produce anything unexpected.

>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
> ---
> Changes in v3:
> - New patch: round to nearest, ties to even, instead of truncating.
> - Amend kstrtox E notation tests and IIO channel write tests for rounding.
> - Link to v2: https://patch.msgid.link/20261013-e-notation-v2-0-d4adb5e193fc@xxxxxxxxxx

...

--
Kind regards,

Rodrigo Alencar