Re: [PATCH RFC 3/3] iio: core: use kstrtodec64() to parse fixed-point values
From: Rodrigo Alencar
Date: Mon Oct 12 2026 - 11:17:16 EST
On 02/10/26 11:00, Andy Shevchenko wrote:
> On Thu, Oct 01, 2026 at 12:34:58PM -0300, Rodrigo Alencar via B4 Relay wrote:
>
> ...
>
> > + /* fract_mult = 10^n, so ffs(10^n) = ffs(2^n * 5^n) = n + 1 */
> > + unsigned int scale = ffs(fract_mult);
>
> Hmm... It's not obvious. Maybe you want to use int_log() instead?
hence the comment. intlog10() from int_log.h returns log10(x) * 2^24.
It could be used with a correction:
DIV_ROUND_CLOSEST(intlog10(x), 1 << 24)
because the header warns the result "might be not exactly n·2²⁴".
Assuming that the fract_mult is a power of 10, ffs is the most straight
forward way of doing this.
--
Kind regards,
Rodrigo Alencar