gtk spinbuttons are crazy - fix possible divide-by-zero

Linus Torvalds torvalds at
Sat Nov 10 06:12:58 PST 2012

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 at>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: application/octet-stream
Size: 644 bytes
Desc: not available
URL: <>

More information about the subsurface mailing list