[<prev] [next>] [day] [month] [year] [list]
Message-ID: <aPPpg9lb-UQ02m-0@ashevche-desk.local>
Date: Sat, 18 Oct 2025 22:24:51 +0300
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: David Lechner <dlechner@...libre.com>
Cc: Jonathan Cameron <jic23@...nel.org>,
Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>, linux-kernel@...r.kernel.org,
linux-iio@...r.kernel.org
Subject: Re: [PATCH] iio: test: fixed-point: new kunit test
On Mon, Oct 13, 2025 at 04:33:43PM -0500, David Lechner wrote:
> Add a kunit test for iio_str_to_fixpoint(). This function has an
> unintuitive API so this is helpful to see how to use it and shows the
> various edge cases.
...
> Discussion unrelated to the patch:
>
> I'm also a little tempted to introduce a new function that is a bit
> easier to use. Many callers of iio_str_to_fixpoint_s64() are doing
> something like int_part * 1000 + fract_part and ignoring the possibility
> of negative values which require special handling.
>
> static int iio_str_to_fixpoint_s64(const char *str, u32 decimal_places, s64 *value)
> {
> int int_part, fract_part;
> int ret;
>
> ret = iio_str_to_fixpoint(str, int_pow(10, decimal_places - 1),
> &int_part, &fract_part);
> if (ret)
> return ret;
>
> *value = (s64)int_part * int_pow(10, decimal_places) +
> (int_part < 0 ? -1 : 1) * fract_part;
Obviously if you go this path, the int_pow() can be called only once
(yes, we would need a multiplication or division for the other case).
The question is how we treat the decimal_places == 0 case.
> return 0;
> }
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists