From dabd6c09fc48b238832e72d92c2b95a407d0f0be Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Mon, 28 Nov 2022 17:27:53 -0800 Subject: [PATCH] twopigen: use an exact comparison when testing against 'UNSET' Squashes a -Wfloat-comparison warning. --- lib/twopigen/circle.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/twopigen/circle.c b/lib/twopigen/circle.c index 13285da9f..6046a5ded 100644 --- a/lib/twopigen/circle.c +++ b/lib/twopigen/circle.c @@ -17,6 +17,7 @@ #include #include #include +#include #define DEF_RANKSEP 1.00 #define UNSET 10.00 @@ -239,6 +240,14 @@ static void setSubtreeSpans(Agraph_t * sg, Agnode_t * center) setChildSubtreeSpans(sg, center); } +/// has the given value been assigned? +static bool is_set(double a) { + // Compare exactly against our sentinel. No need for a tolerance or + // approximation because anything unset has been explicitly assigned `UNSET`. + const double unset = UNSET; + return memcmp(&a, &unset, sizeof(a)) != 0; +} + /* Set the node positions for the 2nd and later rings. */ static void setChildPositions(Agraph_t * sg, Agnode_t * n) { @@ -255,7 +264,7 @@ static void setChildPositions(Agraph_t * sg, Agnode_t * n) next = aghead(ep); if (SPARENT(next) != n) continue; /* handles loops */ - if (THETA(next) != UNSET) + if (is_set(THETA(next))) continue; /* handles multiedges */ THETA(next) = theta + SPAN(next) / 2.0; -- 2.40.0