mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
406e4287eb
commit
2b06a0b223
20 changed files with 109 additions and 100 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue