aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-12-12 12:05:01 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-12-12 07:07:49 -0800
commit767fd39ca05c2a9821329975d1cc1f4f12b18b30 (patch)
treea101d9cbf780cb55a6389fa024d023e8335afec5
parentbf20c251ab2caf37bc3973bbb77201cb0ae7a588 (diff)
downloadsubsurface-767fd39ca05c2a9821329975d1cc1f4f12b18b30.tar.gz
Prevent 0/0 in partial pressure calculation
If for some reason the diluent is pure oxygen, there is a zero divided by zero error in the partial pressure calculation. This patch prevents it. Fixes #774 Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/dive.c b/dive.c
index 78224d82c..19d49bb37 100644
--- a/dive.c
+++ b/dive.c
@@ -1637,8 +1637,12 @@ extern void fill_pressures(struct gas_pressures *pressures, const double amb_pre
pressures->n2 = pressures->he = 0.0;
} else {
pressures->o2 = po2;
- pressures->he = (amb_pressure - pressures->o2) * (double)get_he(mix) / (1000 - get_o2(mix));
- pressures->n2 = amb_pressure - pressures->o2 - pressures->he;
+ if (get_o2(mix) == 1000) {
+ pressures->he = pressures->n2 = 0;
+ } else {
+ pressures->he = (amb_pressure - pressures->o2) * (double)get_he(mix) / (1000 - get_o2(mix));
+ pressures->n2 = amb_pressure - pressures->o2 - pressures->he;
+ }
}
} else { // Open circuit dives: no gas pressure values available, they need to be calculated
pressures->o2 = get_o2(mix) / 1000.0 * amb_pressure; // These calculations are also used if the CCR calculation above..