mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Victor Chernyakin <chernyakin.victor.j@outlook.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] iio: add IIO_VAL_DECIMAL64_{ATTO,ZEPTO,YOCTO} formats
Date: Sun, 25 Oct 2026 21:41:23 +0200	[thread overview]
Message-ID: <at5bYwbaQhFoO0Ac@ashevche-desk.local> (raw)
In-Reply-To: <SN1PR12MB2528A44C0997DAEB1C632F0BA5622@SN1PR12MB2528.namprd12.prod.outlook.com>

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



  reply	other threads:[~2026-10-25 19:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25  5:48 [PATCH v2 0/3] iio: cdc: add Texas Instruments FDC1004 driver Victor Chernyakin
2026-10-25  5:48 ` [PATCH v2 1/3] iio: add IIO_VAL_DECIMAL64_{ATTO,ZEPTO,YOCTO} formats Victor Chernyakin
2026-10-25 19:41   ` Andy Shevchenko [this message]
2026-10-25  5:48 ` [PATCH v2 2/3] dt-bindings: iio: cdc: add Texas Instruments FDC1004 Victor Chernyakin
2026-10-25  5:48 ` [PATCH v2 3/3] iio: cdc: add Texas Instruments FDC1004 driver Victor Chernyakin
2026-10-25 21:24   ` Andy Shevchenko
2026-10-25 20:47 ` [PATCH v2 0/3] " Andy Shevchenko
2026-10-25 21:35   ` Victor Chernyakin
2026-10-25 22:26   ` [PATCH v2 3/3] " Victor Chernyakin
2026-10-25 22:39 ` [PATCH v2 0/3] " Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=at5bYwbaQhFoO0Ac@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=chernyakin.victor.j@outlook.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®