After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 598664 - Comparing floats with == is not safe
Comparing floats with == is not safe
Status: RESOLVED FIXED
Product: gnome-games-superseded
Classification: Deprecated
Component: gnibbles
trunk
Other Linux
: Normal normal
: ---
Assigned To: GNOME Games maintainers
GNOME Games maintainers
Depends on:
Blocks:
 
 
Reported: 2009-10-16 11:24 UTC by Thomas Andersen
Modified: 2009-12-09 23:56 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Thomas Andersen 2009-10-16 11:24:59 UTC
In worm.c gnibbles_worm_get_tail_direction there is a lot of float comparing with == going on.

http://git.gnome.org/cgit/gnome-games/tree/gnibbles/worm.c#n238
Comment 1 Thomas Andersen 2009-10-19 22:08:16 UTC
I have a few comments about the commit. Now I am no expert on floats but isn't the value you compare the absolute difference to supposed to be a very small non-zero number? Like 0.00001 or whatever is appropriate?

http://git.gnome.org/cgit/gnome-games/commit/?id=271ad87eabe1f3f346b294f78b1fbf85c0c567d7
Comment 2 Guillaume Beland 2009-11-18 00:55:54 UTC
Sorry for the late reply, I hadn't CC'ed myself to the bug..

You are right, I'm no expert either and it look like I had the wrong information at that time. So, after looking at proper documentation [1], I made the fix and I'll commit it later. Hopefully, it should be THE safe way to compare float :)

[1] http://www.cygnus-software.com/papers/comparingfloats/Comparing%20floating%20point%20numbers.htm
Comment 3 Thomas Andersen 2009-12-09 23:56:25 UTC
Fixed by Guillaume in:
http://git.gnome.org/cgit/gnome-games/commit/?id=377e7fcafa8e654a236f6b820094179a32bd5513

Thanks