summaryrefslogtreecommitdiffstats
path: root/core/deco.c
diff options
context:
space:
mode:
authorGravatar Jeremie Guichard <djebrest@gmail.com>2017-03-09 23:07:30 +0700
committerGravatar Jeremie Guichard <djebrest@gmail.com>2017-03-09 23:07:30 +0700
commit2b06a0b2234cf2779f80e87038011067be282bcb (patch)
tree7532b11736a5eaedb3ceddf3e85ee423948d47ce /core/deco.c
parent406e4287eb96e10ddfd22163f0e863e353470c68 (diff)
downloadsubsurface-2b06a0b2234cf2779f80e87038011067be282bcb.tar.gz
Fix potential double/float to int rounding errors
Not using lrint(f) when converting double/float to int creates rounding errors. This error was detected by TestParse::testParseDM4 failure on Windows. It was creating rounding inconsistencies on Linux too, see change in TestDiveDM4.xml. Enable -Wfloat-conversion for gcc version greater than 4.9.0 Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
Diffstat (limited to 'core/deco.c')
-rw-r--r--core/deco.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/deco.c b/core/deco.c
index 8247800da..66ed219ee 100644
--- a/core/deco.c
+++ b/core/deco.c
@@ -622,10 +622,10 @@ int deco_allowed_depth(double tissues_tolerance, double surface_pressure, struct
/* Avoid negative depths */
pressure_delta = tissues_tolerance > surface_pressure ? tissues_tolerance - surface_pressure : 0.0;
- depth = rel_mbar_to_depth(pressure_delta * 1000, dive);
+ depth = rel_mbar_to_depth(lrint(pressure_delta * 1000), dive);
if (!smooth)
- depth = ceil(depth / DECO_STOPS_MULTIPLIER_MM) * DECO_STOPS_MULTIPLIER_MM;
+ depth = lrint(ceil(depth / DECO_STOPS_MULTIPLIER_MM) * DECO_STOPS_MULTIPLIER_MM);
if (depth > 0 && depth < buehlmann_config.last_deco_stop_in_mtr * 1000)
depth = buehlmann_config.last_deco_stop_in_mtr * 1000;