]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Do proper rounding in interpolated pressure calculations
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 20 Nov 2011 18:27:33 +0000 (10:27 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 20 Nov 2011 18:27:33 +0000 (10:27 -0800)
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 <torvalds@linux-foundation.org>
profile.c

index 5485ffdc28fc8dba06e5409b9cdd07ce171020a3..aedea192b3583a85f0945259d7dca193105eb6d6 100644 (file)
--- 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];