chiark / gitweb /
Sort out abs/fabs confusion.
authorSimon Tatham <anakin@pobox.com>
Fri, 10 Apr 2015 06:55:16 +0000 (07:55 +0100)
committerSimon Tatham <anakin@pobox.com>
Fri, 10 Apr 2015 06:58:26 +0000 (07:58 +0100)
My Mac has just upgraded itself to include a version of clang which
warns if you use abs() on a floating-point value, or fabs() on an
integer. Fixed the two occurrences that came up in this build (and
which were actual build failures, because of -Werror), one in each
direction.

I think both were benign. The potentially dangerous one was using abs
in place of fabs in grid_find_incentre(), because that could actually
lose precision, but I think that function had plenty of precision to
spare (grid point separation being of the order of tens of pixels) so
nothing should have gone seriously wrong with the old code.

grid.c
signpost.c

diff --git a/grid.c b/grid.c
index bae29f4bfd24e8a649582d4c39d945c657bf0c24..6a90c9942e3a44edff78696e9c6ffd00e554cdce 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -1069,7 +1069,7 @@ void grid_find_incentre(grid_face *f)
                     eq[2] = eqs[0][3]*eqs[1][2] - eqs[1][3]*eqs[0][2];
 
                     /* Parametrise x and y in terms of some t. */
-                    if (abs(eq[0]) < abs(eq[1])) {
+                    if (fabs(eq[0]) < fabs(eq[1])) {
                         /* Parameter is x. */
                         xt[0] = 1; xt[1] = 0;
                         yt[0] = -eq[0]/eq[1]; yt[1] = eq[2]/eq[1];
index 5650b2b67309a7c6f31afdba9de6e912eb7e8c16..9dd8699521b5d7c24784858facf952306d679456 100644 (file)
@@ -1982,7 +1982,7 @@ static void draw_drag_indicator(drawing *dr, game_drawstate *ds,
         /* Draw an arrow pointing away from/towards the origin cell. */
         int ox = COORD(ui->sx) + TILE_SIZE/2, oy = COORD(ui->sy) + TILE_SIZE/2;
         double tana, offset;
-        double xdiff = fabs(ox - ui->dx), ydiff = fabs(oy - ui->dy);
+        double xdiff = abs(ox - ui->dx), ydiff = abs(oy - ui->dy);
 
         if (xdiff == 0) {
             ang = (oy > ui->dy) ? 0.0F : PI;