Re: [PATCH v4 4/6] iio: test: rescale: compare scales against the precision of the output
From: Andy Shevchenko
Date: Mon Oct 26 2026 - 10:45:49 EST
On Mon, Oct 26, 2026 at 08:54:08AM -0300, Rodrigo Alencar via B4 Relay wrote:
>
> The scale tests format the rescaled value with iio_format_value(), which
> prints at most nano precision, and require the relative error to the
> expected value to be below 1 ppm. Both strings are parsed back with
> iio_str_to_fixpoint() at nano precision, so for the small scale cases the
> check only passes because the expected value, like the formatted one, is
> truncated to nano. For example, "0.000000033594" is parsed as 33 nano,
> equal to the formatted "0.000000033", although the actual error is about
> 1.8%. If the expected value were rounded instead, it would be parsed as
> 34 nano and the test would fail even though the output is as accurate as
> the format allows.
>
> Parse both values with kstrtodec64() at a scale of 10, one digit more
> than the output precision, so the expected value keeps the digits lost
> when formatting. Scale 10 is the largest that still fits the overflow
> cases (about 2.1e8) in an s64. Compute the relative error with
> mul_u64_u64_div_u64(), as the product with 10^6 no longer fits in 64 bits
> for those cases.
>
> Then allow a relative error up to the relative size of one nano of the
> expected value, the precision of the formatted output. This is 0 ppm for
> values of 0.01 and above, so those cases are checked as before, and it
> accepts the formatting error for the small scale cases.
...
> +/*
> + * iio_format_value() prints scales with up to nano precision. Parse values
> + * with one more digit, so the expected values keep the precision lost there.
> + * Scale 10 is the largest that fits the overflow test cases in an s64.
> */
> +#define IIO_TEST_DEC_SCALE 10
> +#define IIO_TEST_NANO 10 /* one nano at IIO_TEST_DEC_SCALE */
I would put them as (9 + 1) to show that actually show that "with one more digit".
I also don't follow the comment near to the last definition. What does it mean?
--
With Best Regards,
Andy Shevchenko