[gnome-games] gnibbles: proper safe float comparison



commit 377e7fcafa8e654a236f6b820094179a32bd5513
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Wed Nov 18 21:12:48 2009 -0500

    gnibbles: proper safe float comparison

 gnibbles/worm.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/gnibbles/worm.c b/gnibbles/worm.c
index 669d575..a200db9 100644
--- a/gnibbles/worm.c
+++ b/gnibbles/worm.c
@@ -255,13 +255,13 @@ gnibbles_worm_get_tail_direction (GnibblesWorm *worm)
   xdiff = MAX (x2,x1) - MIN (x2,x1);
   ydiff = MAX (y2,y1) - MIN (y2,y1);
 
-  if (x2 > x1 && fabs (y1 - y2) <= 0)
+  if (x2 > x1 && fabs (y1 - y2) < 0.0001)
     return xdiff > properties->tilesize ? WORMLEFT : WORMRIGHT;
-  else if (x2 < x1 && fabs (y1 - y2) <= 0)
+  else if (x2 < x1 && fabs (y1 - y2) < 0.0001)
     return xdiff > properties->tilesize ? WORMRIGHT : WORMLEFT;
-  else if (y2 > y1 && fabs (x1 - x2) <= 0)
+  else if (y2 > y1 && fabs (x1 - x2) < 0.0001)
     return ydiff > properties->tilesize ? WORMUP: WORMDOWN;
-  else if (y2 < y1 && fabs (x1 - x2) <= 0)
+  else if (y2 < y1 && fabs (x1 - x2) < 0.0001)
     return ydiff > properties->tilesize ? WORMDOWN : WORMUP;
   else
     return -1;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]