diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-08-29 20:05:20 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-08-29 21:43:19 -0700 |
commit | d8a6b917a5ec2d3be40908864d74faed8b0e47b2 (patch) | |
tree | 95d6bb5163824327cc23355a69f85a7a31c70f60 | |
parent | 5a66ac7698afbe82e3d55549fd63590918d0a3d9 (diff) | |
download | subsurface-d8a6b917a5ec2d3be40908864d74faed8b0e47b2.tar.gz |
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>
-rw-r--r-- | core/dive.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/core/dive.h b/core/dive.h index ae980947a..13ad6b509 100644 --- a/core/dive.h +++ b/core/dive.h @@ -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) { /* It is doubtful that we actually need floating point for this, but whatever */ - double x = (double)a * (whole - part) + (double)b * part; - return rint(x / whole); + if (whole) { + double x = (double)a * (whole - part) + (double)b * part; + return rint(x / whole); + } + return (a+b)/2; } void get_gas_string(const struct gasmix *gasmix, char *text, int len); |