summaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-03-18 09:28:30 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-03-30 16:02:21 -0700
commit374f99af180c0008a292432c4eeed3f299dbf939 (patch)
treeccb84b6744b4e856682f71a15deb0923d8e1d6fd /profile.c
parent0cd9d09410e2631d3a47edcae7569e3b3f011cf1 (diff)
downloadsubsurface-374f99af180c0008a292432c4eeed3f299dbf939.tar.gz
Get rid of division by 0 by reshuffling EAD and EAN logic
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/profile.c b/profile.c
index 58a29d9c4..c3055dea8 100644
--- a/profile.c
+++ b/profile.c
@@ -1130,16 +1130,19 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
amb_pressure = depth_to_mbar(entry->depth, dive) / 1000.0;
fo2 = get_o2(&dive->cylinder[cylinderindex].gasmix);
fhe = get_he(&dive->cylinder[cylinderindex].gasmix);
- double ratio = (fo2 == 1000) ? 0 : (double)fhe / (1000.0 - fo2);
if (entry->po2) {
/* we have an O2 partial pressure in the sample - so this
* is likely a CC dive... use that instead of the value
* from the cylinder info */
- double po2 = entry->po2 > amb_pressure ? amb_pressure : entry->po2;
- entry->po2 = po2;
- entry->phe = (amb_pressure - po2) * ratio;
- entry->pn2 = amb_pressure - po2 - entry->phe;
+ if (entry->po2 >= amb_pressure || fo2 == 1000) {
+ entry->po2 = amb_pressure;
+ entry->phe = 0;
+ entry->pn2 = 0;
+ } else {
+ entry->phe = (amb_pressure - entry->po2) * (double)fhe / (1000 - fo2);
+ entry->pn2 = amb_pressure - entry->po2 - entry->phe;
+ }
} else {
entry->po2 = fo2 / 1000.0 * amb_pressure;
entry->phe = fhe / 1000.0 * amb_pressure;
@@ -1151,10 +1154,8 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
* EAD takes O2 + N2 (air) into account
* END just uses N2 */
entry->mod = (prefs.mod_ppO2 / fo2 * 1000 - 1) * 10000;
- entry->ead = (entry->depth + 10000) *
- (entry->po2 + (amb_pressure - entry->po2) * (1 - ratio)) / amb_pressure - 10000;
- entry->end = (entry->depth + 10000) *
- (amb_pressure - entry->po2) * (1 - ratio) / amb_pressure / N2_IN_AIR * 1000 - 10000;
+ entry->ead = (entry->depth + 10000) * (1000 - fhe) / 1000.0 - 10000;
+ entry->end = (entry->depth + 10000) * (1000 - fo2 - fhe) / (double)N2_IN_AIR - 10000;
entry->eadd = (entry->depth + 10000) *
(entry->po2 / amb_pressure * O2_DENSITY + entry->pn2 / amb_pressure *
N2_DENSITY +