diff options
author | Robert C. Helling <helling@atdotde.de> | 2020-11-13 09:38:08 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-11-13 11:10:48 -0800 |
commit | 10bedf02d03ab0d855385abd233881f56ab7e023 (patch) | |
tree | 12f829e5542eca5b5df8c22a676bcd80235cbbc0 /core/dive.c | |
parent | 78da1869ce55418d83e95b219a6bd691e8ead2bc (diff) | |
download | subsurface-10bedf02d03ab0d855385abd233881f56ab7e023.tar.gz |
Gracefully handle infinite MND for oxygen
When breathing pure oxygen and considering it not
narcotic, there is not maximal narcotic depth and
the formula divides by zero. So better, handle this
case separately.
Fixes #3080
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'core/dive.c')
-rw-r--r-- | core/dive.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/core/dive.c b/core/dive.c index 177c91990..6ac70da71 100644 --- a/core/dive.c +++ b/core/dive.c @@ -3253,7 +3253,11 @@ depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int rou int maxambient = prefs.o2narcotic ? (int)lrint(ppo2n2.mbar / (1 - get_he(mix) / 1000.0)) : - (int)lrint(ppo2n2.mbar * N2_IN_AIR / get_n2(mix)); + get_n2(mix) > 0 ? + (int)lrint(ppo2n2.mbar * N2_IN_AIR / get_n2(mix)) + : + // Actually: Infinity + 1000000; rounded_depth.mm = (int)lrint(((double)mbar_to_depth(maxambient, dive)) / roundto) * roundto; return rounded_depth; } |