summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2014-11-07 09:04:47 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-07 13:12:22 -0800
commit09e8adf54eac5159b393b9a09799663060c01db1 (patch)
tree5228b99ba1add478121f790e3c2de0ecaeda687c
parent450093df85c38ce33fd23049a77750cf48e03976 (diff)
downloadsubsurface-09e8adf54eac5159b393b9a09799663060c01db1.tar.gz
Convert volume calculations into floating point
The basic problem was that for gases containing more than 2147483648 ml of nitrogen the calculations overflowed. This changes the code into using floating point math for that calculation which will be more accurate to. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--statistics.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/statistics.c b/statistics.c
index 17667f899..9eb029115 100644
--- a/statistics.c
+++ b/statistics.c
@@ -342,8 +342,8 @@ static void get_gas_parts(struct gasmix mix, volume_t vol, int o2_in_topup, volu
return;
}
- air.mliter = (vol.mliter * (1000 - get_he(&mix) - get_o2(&mix))) / (1000 - o2_in_topup);
- he->mliter = (vol.mliter * get_he(&mix)) / 1000;
+ air.mliter = rint(((double)vol.mliter * (1000 - get_he(&mix) - get_o2(&mix))) / (1000 - o2_in_topup));
+ he->mliter = rint(((double)vol.mliter * get_he(&mix)) / 1000.0);
o2->mliter += vol.mliter - he->mliter - air.mliter;
}