diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-01-06 23:33:42 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-07 07:33:22 -0800 |
commit | 1ee0101b280d582bbdea87ae9ae9c67314ea6fb1 (patch) | |
tree | 092bc05d215ab85471b80a2e0b5d788a00954113 /profile.c | |
parent | d85d8421e08583a8132cc3e0c5dd2b9415a8e091 (diff) | |
download | subsurface-1ee0101b280d582bbdea87ae9ae9c67314ea6fb1.tar.gz |
Don't bother with "correct" units for the pressure_time calculation
I fixed the pressure-time calculations to use "proper" units, but
thinking about it some more, it turns out that units don't really
matter. As long as we use the *same* unit for calculating the
integral, and then re-calculating the step-wise entries, the units
will cancel out.
So we can simplify the "pressure_time()" function a bit, and use
whatever units are most natural for our internal representation. So
instead of using atm, use "mbar".
Now, since the units don't matter, this patch doesn't really make much
of a difference conceptually. Sure, it's a slightly simpler function,
but maybe using more "natural" units for it would be worth it. But it
turns out that using milli-bar and seconds has an advantage: we could
do all the pressure_time integral using 32-bit integers, and we'd
still be able to represent values that would be equivalent to staying
at 24 bar for a whole day.
This patch doesn't actually change the code to use integers, but with
this unit choice, we at least have that possibility.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -1394,14 +1394,19 @@ static void fill_missing_segment_pressures(pr_track_t *list) * What's the pressure-time between two plot data entries? * We're calculating the integral of pressure over time by * adding these up. + * + * The units won't matter as long as everybody agrees about + * them, since they'll cancel out - we use this to calculate + * a constant SAC-rate-equivalent, but we only use it to + * scale pressures, so it ends up being a unitless scaling + * factor. */ static inline double pressure_time(struct dive *dive, struct plot_data *a, struct plot_data *b) { int time = b->sec - a->sec; int depth = (a->depth + b->depth)/2; - int mbar = depth_to_mbar(depth, dive); - return bar_to_atm(mbar / 1000.0) * time; + return depth_to_mbar(depth, dive) * time; } static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi, pr_track_t **track_pr) |