From: Matthew Fernandez Date: Thu, 20 Aug 2020 00:03:10 +0000 (-0700) Subject: use fabs() instead of ABS() for taking the absolute value of a double X-Git-Tag: 2.46.0~20^2^2~112^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b88ebe0548dd412ea415d6cfc410d91117270277;p=graphviz use fabs() instead of ABS() for taking the absolute value of a double 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. --- diff --git a/lib/common/routespl.c b/lib/common/routespl.c index 51ed86c03..44b733c31 100644 --- a/lib/common/routespl.c +++ b/lib/common/routespl.c @@ -14,6 +14,7 @@ #include "config.h" #include "render.h" +#include #include "pathplan.h" #include #include @@ -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]; diff --git a/lib/common/splines.c b/lib/common/splines.c index da29e86d9..66d7e5558 100644 --- a/lib/common/splines.c +++ b/lib/common/splines.c @@ -16,6 +16,7 @@ * an edge, starting from a list of control points. */ +#include #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]; diff --git a/lib/common/utils.c b/lib/common/utils.c index c71f72f6d..35efa9733 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -16,6 +16,7 @@ #include "htmltable.h" #include "entities.h" #include "logic.h" +#include #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; diff --git a/lib/dotgen/sameport.c b/lib/dotgen/sameport.c index f5ce02b0f..6c9b227e1 100644 --- a/lib/dotgen/sameport.c +++ b/lib/dotgen/sameport.c @@ -16,6 +16,7 @@ * merge edges with specified samehead/sametail onto the same port */ +#include #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; } } diff --git a/lib/neatogen/stress.c b/lib/neatogen/stress.c index 52b25af45..e8ade2dd0 100644 --- a/lib/neatogen/stress.c +++ b/lib/neatogen/stress.c @@ -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)); } diff --git a/lib/pathplan/route.c b/lib/pathplan/route.c index bf253f73f..8aeef35fd 100644 --- a/lib/pathplan/route.c +++ b/lib/pathplan/route.c @@ -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;