Re: [PATCH v2] power: supply: core: Use library interpolation

Linus Walleij
2021-11-16T13:34:23Z

On Tue, Nov 16, 2021 at 3:28 AM Baolin Wang
<baolin.wang@linux.alibaba.com> wrote:

> Thanks for your patch, and overall looks good to me. But I still think
> we should not do interpolation if the temperature is larger than the
> maximum value of the table, we can just return the maximum value of the
> table instead. Something like below untested code, how do you think?

You are right, but if I understand correctly
fixp_linear_interpolate() already does what you want,
perhaps a bit unintuitively. See include/linux/fixp-arith.h:

static inline int fixp_linear_interpolate(int x0, int y0, int x1, int y1, int x)
{
if (y0 == y1 || x == x0)
return y0;
if (x1 == x0 || x == x1)
return y1;

return y0 + ((y1 - y0) * (x - x0) / (x1 - x0));
}

Yours,
Linus Walleij