From a643e740dc32d474cc4f0ff3f0187418463e44e1 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 20 Nov 2011 10:27:33 -0800 Subject: [PATCH] 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 --- profile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]; -- 2.45.2