From: Linus Torvalds Date: Sun, 20 Nov 2011 18:27:33 +0000 (-0800) Subject: Do proper rounding in interpolated pressure calculations X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a643e740dc32d474cc4f0ff3f0187418463e44e1;p=ext%2Fsubsurface.git Do proper rounding in interpolated pressure calculations We do all the pressures in mbar, which has plenty of precision for interpolated pressures - even when we then do our discrete integration over many samples. However, when we calculate those interpolated pressure points, we should make sure that we round the result correctly, otherwise the consistent rounding errors (from truncating the FP value into our integer mbar values) will result in a final pressure that is noticeably off in ugly ways (ie "end pressure set by hand to 750 mbar, but shown as 748"). Signed-off-by: Linus Torvalds --- diff --git a/profile.c b/profile.c index 5485ffd..aedea19 100644 --- a/profile.c +++ b/profile.c @@ -1001,7 +1001,7 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi, double cur_pt = (entry->sec - (entry-1)->sec) * (1 + (entry->depth + (entry-1)->depth) / 20000.0); INTERPOLATED_PRESSURE(entry) = - cur_pr[entry->cylinderindex] + cur_pt * magic; + cur_pr[entry->cylinderindex] + cur_pt * magic + 0.5; cur_pr[entry->cylinderindex] = INTERPOLATED_PRESSURE(entry); } else INTERPOLATED_PRESSURE(entry) = cur_pr[entry->cylinderindex];