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>
This commit is contained in:
Jeremie Guichard 2017-03-09 23:07:30 +07:00
parent 406e4287eb
commit 2b06a0b223
20 changed files with 109 additions and 100 deletions

View file

@ -68,15 +68,15 @@ static void process_dive(struct dive *dp, stats_t *stats)
return;
if (dp->meandepth.mm) {
stats->total_average_depth_time.seconds += duration;
stats->avg_depth.mm = (1.0 * old_tadt * stats->avg_depth.mm +
duration * dp->meandepth.mm) /
stats->total_average_depth_time.seconds;
stats->avg_depth.mm = lrint((1.0 * old_tadt * stats->avg_depth.mm +
duration * dp->meandepth.mm) /
stats->total_average_depth_time.seconds);
}
if (dp->sac > 100) { /* less than .1 l/min is bogus, even with a pSCR */
sac_time = stats->total_sac_time + duration;
stats->avg_sac.mliter = (1.0 * stats->total_sac_time * stats->avg_sac.mliter +
stats->avg_sac.mliter = lrint((1.0 * stats->total_sac_time * stats->avg_sac.mliter +
duration * dp->sac) /
sac_time;
sac_time);
if (dp->sac > stats->max_sac.mliter)
stats->max_sac.mliter = dp->sac;
if (stats->min_sac.mliter == 0 || dp->sac < stats->min_sac.mliter)