Re: [PATCH v13 06/12] iio: core: add decimal value formatting into 64-bit value

From: Andy Shevchenko

Date: Sun May 17 2026 - 06:16:17 EST


On Sun, May 17, 2026 at 10:14:01AM +0100, Rodrigo Alencar via B4 Relay wrote:

> Create new format types for iio values (IIO_VAL_DECIMAL64_*), which
> defines the representation of fixed decimal point values into a single
> 64-bit number. This new format increases the range of represented values,
> allowing for integer parts greater than 2^32, as bits are not "wasted"
> in the fractional part, which can be seen in IIO_VAL_INT_PLUS_MICRO and
> IIO_VAL_INT_PLUS_NANO. Helpers are created to compose and decompose 64-bit
> decimals into integer values used in IIO formatting interfaces, which
> creates consistency and avoid error-prone manual assignments when using
> wordpart macros. When doing the parsing, kstrtodec64() is used with the
> scale defined by the specific decimal format type.

...

> + {
> + int scale = type - IIO_VAL_DECIMAL64_BASE;

> + int l = 0;

Perhaps make it global in the function? We have the same in
IIO_VAL_INT_MULTIPLE case.

> + s64 frac;
> +
> + tmp2 = div64_s64_rem(iio_val_s64_from_s32s(vals),
> + int_pow(10, scale), &frac);
> + if (tmp2 == 0 && frac < 0)
> + l += sysfs_emit_at(buf, offset, "-");
> +
> + l += sysfs_emit_at(buf, offset + l, "%lld.%0*lld", tmp2, scale,
> + abs(frac));
> + return l;
> + }

...

> #ifndef _IIO_TYPES_H_
> #define _IIO_TYPES_H_

Also needs types.h now... Which makes me think if the proposed macros are
placed in the good enough location.

(Note, iio/iio.h missing actually types.h, but includes it indirectly.)

--
With Best Regards,
Andy Shevchenko