diff options
author | Jeremie Guichard <djebrest@gmail.com> | 2017-03-09 23:07:30 +0700 |
---|---|---|
committer | Jeremie Guichard <djebrest@gmail.com> | 2017-03-09 23:07:30 +0700 |
commit | 2b06a0b2234cf2779f80e87038011067be282bcb (patch) | |
tree | 7532b11736a5eaedb3ceddf3e85ee423948d47ce /core/divelist.c | |
parent | 406e4287eb96e10ddfd22163f0e863e353470c68 (diff) | |
download | subsurface-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/divelist.c')
-rw-r--r-- | core/divelist.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/core/divelist.c b/core/divelist.c index d47b034bd..f3465830e 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -178,7 +178,7 @@ static int calculate_otu(struct dive *dive) po2 = sample->setpoint.mbar; } else { int o2 = active_o2(dive, dc, sample->time); - po2 = o2 * depth_to_atm(sample->depth.mm, dive); + po2 = lrint(o2 * depth_to_atm(sample->depth.mm, dive)); } if (po2 >= 500) otu += pow((po2 - 500) / 1000.0, 0.83) * t / 30.0; @@ -243,7 +243,7 @@ static int calculate_cns(struct dive *dive) po2 = sample->setpoint.mbar; } else { int o2 = active_o2(dive, dc, sample->time); - po2 = o2 * depth_to_atm(sample->depth.mm, dive); + po2 = lrint(o2 * depth_to_atm(sample->depth.mm, dive)); } /* CNS don't increse when below 500 matm */ if (po2 < 500) @@ -256,7 +256,7 @@ static int calculate_cns(struct dive *dive) cns += ((double)t) / ((double)cns_table[j][1]) * 100; } /* save calculated cns in dive struct */ - dive->cns = cns; + dive->cns = lrint(cns); return dive->cns; } /* @@ -305,7 +305,7 @@ static int calculate_sac(struct dive *dive) sac = airuse / pressure * 60 / duration; /* milliliters per minute.. */ - return sac * 1000; + return lrint(sac * 1000); } /* for now we do this based on the first divecomputer */ |