blob: acb213acd0a5b65a2fd36d50afa5155d863ea3c1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
// SPDX-License-Identifier: GPL-2.0
#ifndef INTERPOLATE_H
#define INTERPOLATE_H
/* Linear interpolation between 'a' and 'b', when we are 'part'way into the 'whole' distance from a to b */
static inline int interpolate(int a, int b, int part, int whole)
{
/* It is doubtful that we actually need floating point for this, but whatever */
if (whole) {
double x = (double)a * (whole - part) + (double)b * part;
return (int)lrint(x / whole);
}
return (a+b)/2;
}
#endif
|