aboutsummaryrefslogtreecommitdiffstats
path: root/core/file.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/file.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/file.c')
-rw-r--r--core/file.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/core/file.c b/core/file.c
index 5b910e72b..889a9102b 100644
--- a/core/file.c
+++ b/core/file.c
@@ -293,31 +293,31 @@ static void add_sample_data(struct sample *sample, enum csv_format type, double
sample->cylinderpressure.mbar = psi_to_mbar(val * 4);
break;
case POSEIDON_DEPTH:
- sample->depth.mm = val * 0.5 *1000;
+ sample->depth.mm = lrint(val * 0.5 * 1000);
break;
case POSEIDON_TEMP:
sample->temperature.mkelvin = C_to_mkelvin(val * 0.2);
break;
case POSEIDON_SETPOINT:
- sample->setpoint.mbar = val * 10;
+ sample->setpoint.mbar = lrint(val * 10);
break;
case POSEIDON_SENSOR1:
- sample->o2sensor[0].mbar = val * 10;
+ sample->o2sensor[0].mbar = lrint(val * 10);
break;
case POSEIDON_SENSOR2:
- sample->o2sensor[1].mbar = val * 10;
+ sample->o2sensor[1].mbar = lrint(val * 10);
break;
case POSEIDON_PRESSURE:
- sample->cylinderpressure.mbar = val * 1000;
+ sample->cylinderpressure.mbar = lrint(val * 1000);
break;
case POSEIDON_O2CYLINDER:
- sample->o2cylinderpressure.mbar = val * 1000;
+ sample->o2cylinderpressure.mbar = lrint(val * 1000);
break;
case POSEIDON_NDL:
- sample->ndl.seconds = val * 60;
+ sample->ndl.seconds = lrint(val * 60);
break;
case POSEIDON_CEILING:
- sample->stopdepth.mm = val * 1000;
+ sample->stopdepth.mm = lrint(val * 1000);
break;
}
}