diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-11-10 15:12:58 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-11-10 16:00:54 +0100 |
commit | 080bcc10fc5e1651bc31f2260ef85376a8356c0b (patch) | |
tree | 62e7d157b4892940a94f96ef61237b71b990bf38 /equipment.c | |
parent | 07de22a5d0d5b6aa189ea9a59951dc82fc031ba0 (diff) | |
download | subsurface-080bcc10fc5e1651bc31f2260ef85376a8356c0b.tar.gz |
gtk spinbuttons are crazy - fix possible divide-by-zero
When we fill the cylinder information in an imperial unit world, a
working pressure of zero is a special case, and forces us to use the
actual physical size of the cylinder in liter, despite the fact that
we normally would use cuft.
However, we compare that value against zero in a 'double', and in
between going through the gtk spinbutton logic, the zero we have
filled in then gets read out as some very tiny epsilon value from the
gtk spinbuttons (typically in the 10**-317 range). This causes us to
think that the zero isn't actually a zero, because gtk has done odd
things with it.
Fix this by calculating the millibar value (as an integer) first, and
check that *integer* against zero. Any crazy epsilon values will have
been rounded away, and our logic works again.
There's a good reason why subsurface does everything using integers
(ie the afore-mentioned "convert to integer millibar" etc) and doesn't
use floating point for any core data structures, only for conversion.
FP rounding and inexact behavior can be really subtle.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'equipment.c')
-rw-r--r-- | equipment.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/equipment.c b/equipment.c index c709207ee..8bfb7a7a8 100644 --- a/equipment.c +++ b/equipment.c @@ -637,13 +637,13 @@ static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl end = psi_to_bar(end); } - if (pressure && output_units.volume == CUFT) { + mbar = pressure * 1000 + 0.5; + if (mbar && output_units.volume == CUFT) { volume = cuft_to_l(volume); volume /= bar_to_atm(pressure); } ml = volume * 1000 + 0.5; - mbar = pressure * 1000 + 0.5; /* Ignore obviously crazy He values */ if (o2 + he > 1000) |