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>
This commit is contained in:
Linus Torvalds 2012-11-10 15:12:58 +01:00 committed by Dirk Hohndel
parent 07de22a5d0
commit 080bcc10fc

View file

@ -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)