]> granicus.if.org Git - graphviz/commitdiff
use fabs() instead of ABS() for taking the absolute value of a double
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 20 Aug 2020 00:03:10 +0000 (17:03 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 25 Aug 2020 14:27:53 +0000 (07:27 -0700)
The fabs() function is available via math.h, even prior to C89 so there's no
reason not to use it. Avoiding the macro eliminates some mental overhead for the
reader. Also fabs has some more lenient semantics with respect to denormal
inputs, so this change results in slightly more efficient code.

lib/common/routespl.c
lib/common/splines.c
lib/common/utils.c
lib/dotgen/sameport.c
lib/neatogen/stress.c
lib/pathplan/route.c

index 51ed86c03b9b04f5eda939c0900317b0227ecb4e..44b733c319ffdc967498a130f7073ae216a245db 100644 (file)
@@ -14,6 +14,7 @@
 #include "config.h"
 
 #include "render.h"
+#include <math.h>
 #include "pathplan.h"
 #include <setjmp.h>
 #include <stdlib.h>
@@ -695,9 +696,9 @@ static int checkpath(int boxn, boxf* boxes, path* thepath)
     /* remove degenerate boxes. */
     i = 0;
     for (bi = 0; bi < boxn; bi++) {
-       if (ABS(boxes[bi].LL.y - boxes[bi].UR.y) < .01)
+       if (fabs(boxes[bi].LL.y - boxes[bi].UR.y) < .01)
            continue;
-       if (ABS(boxes[bi].LL.x - boxes[bi].UR.x) < .01)
+       if (fabs(boxes[bi].LL.x - boxes[bi].UR.x) < .01)
            continue;
        if (i != bi)
            boxes[i] = boxes[bi];
index da29e86d98e601989297019d668d73348f8e4622..66d7e5558d5c39c637ba14a68cdee5b6e2c7c99e 100644 (file)
@@ -16,6 +16,7 @@
  * an edge, starting from a list of control points.
  */
 
+#include <math.h>
 #include "render.h"
 
 #ifdef DEBUG
@@ -140,7 +141,7 @@ void bezier_clip(inside_t * inside_context,
            found = TRUE;
            *odir = t;
        }
-    } while (ABS(opt.x - pt.x) > .5 || ABS(opt.y - pt.y) > .5);
+    } while (fabs(opt.x - pt.x) > .5 || fabs(opt.y - pt.y) > .5);
     if (found)
        for (i = 0; i < 4; i++)
            sp[i] = best[i];
index c71f72f6d9219debcbdf73ab696a07f7f6541e7b..35efa97332aaa3d4a4c3c1fafdc56bdf68dd07fc 100644 (file)
@@ -16,6 +16,7 @@
 #include "htmltable.h"
 #include "entities.h"
 #include "logic.h"
+#include <math.h>
 #include "gvc.h"
 #include "strcasecmp.h"
 
@@ -591,7 +592,7 @@ pointf spline_at_y(splines * spl, double y)
            t = (low + high) / 2.0;
            p = Bezier(c, 3, t, NULL, NULL);
            d = p.y - y;
-           if (ABS(d) <= 1)
+           if (fabs(d) <= 1)
                break;
            if (d < 0)
                high = t;
index f5ce02b0f5fdd543c4ae1eced780f44b357b55f0..6c9b227e148e08d308814bd1312da4736447e1ad 100644 (file)
@@ -16,6 +16,7 @@
  *     merge edges with specified samehead/sametail onto the same port
  */
 
+#include <math.h>
 #include       "dot.h"
 
 
@@ -206,11 +207,11 @@ nodes and maintaining equal separation when specified
           FIXME: I guess this adds an extra box for all edges in the rank */
        if (u == l->list[0]->head) {
            if (GD_rank(u->graph)[ND_rank(u)].ht2 <
-               (ht = ABS(arr_prt.p.y)))
+               (ht = fabs(arr_prt.p.y)))
                GD_rank(u->graph)[ND_rank(u)].ht2 = ht;
        } else {
            if (GD_rank(u->graph)[ND_rank(u)].ht1 <
-               (ht = ABS(arr_prt.p.y)))
+               (ht = fabs(arr_prt.p.y)))
                GD_rank(u->graph)[ND_rank(u)].ht1 = ht;
        }
     }
index 52b25af457588707b09300292002b44a99944f09..e8ade2dd0189a823dbf86c24b17f019ec8a29b8f 100644 (file)
@@ -1249,7 +1249,7 @@ int stress_majorization_kD_mkernel(vtx_data * graph,      /* Input graph in sparse re
         */
        {
            double diff = old_stress - new_stress;
-           double change = ABS(diff);
+           double change = fabs(diff);
            converged = (((change / old_stress) < Epsilon)
                         || (new_stress < Epsilon));
        }
index bf253f73f36be769ba01d35e3acae30b6f6becc8..8aeef35fdc0704f95691a83716795d0a1acef4ab 100644 (file)
@@ -268,11 +268,11 @@ static int mkspline(Ppoint_t * inps, int inpn, tna_t * tnas, Ppoint_t ev0,
     det01 = c[0][0] * c[1][1] - c[1][0] * c[0][1];
     det0X = c[0][0] * x[1] - c[0][1] * x[0];
     detX1 = x[0] * c[1][1] - x[1] * c[0][1];
-    if (ABS(det01) >= 1e-6) {
+    if (fabs(det01) >= 1e-6) {
        scale0 = detX1 / det01;
        scale3 = det0X / det01;
     }
-    if (ABS(det01) < 1e-6 || scale0 <= 0.0 || scale3 <= 0.0) {
+    if (fabs(det01) < 1e-6 || scale0 <= 0.0 || scale3 <= 0.0) {
        d01 = dist(inps[0], inps[inpn - 1]) / 3.0;
        scale0 = d01;
        scale3 = d01;