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/datatrak.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/datatrak.c')
-rw-r--r-- | core/datatrak.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/core/datatrak.c b/core/datatrak.c index ab888977c..d46167cc8 100644 --- a/core/datatrak.c +++ b/core/datatrak.c @@ -384,7 +384,7 @@ bool dt_dive_parser(FILE *archivo, struct dive *dt_dive) */ read_bytes(2); if (tmp_2bytes != 0x7FFF && dt_dive->cylinder[0].type.size.mliter) - dt_dive->cylinder[0].gas_used.mliter = dt_dive->cylinder[0].type.size.mliter * (tmp_2bytes / 100.0); + dt_dive->cylinder[0].gas_used.mliter = lrint(dt_dive->cylinder[0].type.size.mliter * (tmp_2bytes / 100.0)); /* * Dive Type 1 - Bit table. Subsurface don't have this record, but @@ -625,7 +625,7 @@ bool dt_dive_parser(FILE *archivo, struct dive *dt_dive) read_bytes(1); if (is_nitrox) { dt_dive->cylinder[0].gasmix.o2.permille = - (tmp_1byte & 0x0F ? 20.0 + 2 * (tmp_1byte & 0x0F) : 21.0) * 10; + lrint((tmp_1byte & 0x0F ? 20.0 + 2 * (tmp_1byte & 0x0F) : 21.0) * 10); } else { dt_dive->cylinder[0].gasmix.o2.permille = tmp_1byte * 10; read_bytes(1) // Jump over one byte, unknown use |