Re: [PATCH v2 1/3] iio: add IIO_VAL_DECIMAL64_{ATTO,ZEPTO,YOCTO} formats

From: Andy Shevchenko

Date: Sun Oct 25 2026 - 15:41:52 EST


On Sun, Oct 25, 2026 at 12:48:04AM -0500, Victor Chernyakin wrote:
> The highest-precision format IIO has right now is IIO_VAL_DECIMAL64_FEMTO,
> which gives 15 decimal digits of precision after the decimal point. This
> is not enough for the upcoming TI FDC1004 driver, which needs 22 digits
> of precision to exactly express its scale value. This patch adds higher-
> precision formats, up to IIO_VAL_DECIMAL64_YOCTO (24 digits of precision).

...

> +/* An abs() function that doesn't have undefined behavior for LLONG_MIN. */

Can you elaborate how so?

> +static inline u64 abs_s64_no_overflow(s64 x)
> +{
> + return x < 0 ? -(u64)x : (u64)x;
> +}

So, the trick you use is to update the type from signed to unsigned.
'-' operator is always defined on unsigned types and produces modulo
results in case the representation requires more bits than type has.

FWIW, it's not MISRA-compliant :-)

--
With Best Regards,
Andy Shevchenko