mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Teach 'interpolate()' about zero-sized ranges
No, they don't make sense. We should normally not have multiple samples that are on the same second. But they seem to happen on the EON Steel under some circumstances, and instead of dividing by zero when trying to interpolate across such a sample, do something sane. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5a66ac7698
commit
d8a6b917a5
1 changed files with 5 additions and 2 deletions
|
@ -169,8 +169,11 @@ static inline bool gasmix_is_air(const struct gasmix *gasmix)
|
||||||
static inline int interpolate(int a, int b, int part, int whole)
|
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 */
|
/* It is doubtful that we actually need floating point for this, but whatever */
|
||||||
|
if (whole) {
|
||||||
double x = (double)a * (whole - part) + (double)b * part;
|
double x = (double)a * (whole - part) + (double)b * part;
|
||||||
return rint(x / whole);
|
return rint(x / whole);
|
||||||
|
}
|
||||||
|
return (a+b)/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_gas_string(const struct gasmix *gasmix, char *text, int len);
|
void get_gas_string(const struct gasmix *gasmix, char *text, int len);
|
||||||
|
|
Loading…
Add table
Reference in a new issue