iio: afe: rescale: fix accuracy for small fractional scales
authorLiam Beguin <liambeguin@gmail.com>
Sun, 13 Feb 2022 02:57:33 +0000 (21:57 -0500)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 27 Feb 2022 13:38:16 +0000 (13:38 +0000)
commitf5fc003d48033559314f1c9de8198f58f14ed557
tree40f62414836f50503b083c7113ebe3777631b47a
parenta29c3283653b80b916c5ca5292c5d36415e38e92
iio: afe: rescale: fix accuracy for small fractional scales

The approximation caused by integer divisions can be costly on smaller
scale values since the decimal part is significant compared to the
integer part. Switch to an IIO_VAL_INT_PLUS_NANO scale type in such
cases to maintain accuracy.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
Reviewed-by: Peter Rosin <peda@axentia.se>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220213025739.2561834-5-liambeguin@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/afe/iio-rescale.c