From 87e5f09258a86ec5b77c771fe9b1a155cb08f564 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 19 Dec 2021 11:37:41 -0800 Subject: [PATCH] dijkstra.c: use standard 'FLT_MAX' instead of 'MAXFLOAT' MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This code is simply relying on some initial value that is “larger than any reasonable result from the following computation.” So `FLT_MAX` is clearer and more portable. --- lib/neatogen/dijkstra.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/neatogen/dijkstra.c b/lib/neatogen/dijkstra.c index d55f7eb22..37b1e7ce8 100644 --- a/lib/neatogen/dijkstra.c +++ b/lib/neatogen/dijkstra.c @@ -18,6 +18,7 @@ ******************************************/ #include +#include #include #include #include @@ -343,7 +344,7 @@ void dijkstra_f(int vertex, vtx_data * graph, int n, float *dist) /* initial distances with edge weights: */ for (i = 0; i < n; i++) - dist[i] = MAXFLOAT; + dist[i] = FLT_MAX; dist[vertex] = 0; for (i = 1; i < graph[vertex].nedges; i++) dist[graph[vertex].edges[i]] = graph[vertex].ewgts[i]; @@ -352,7 +353,7 @@ void dijkstra_f(int vertex, vtx_data * graph, int n, float *dist) while (extractMax_f(&H, &closestVertex, index, dist)) { closestDist = dist[closestVertex]; - if (closestDist == MAXFLOAT) + if (closestDist == FLT_MAX) break; for (i = 1; i < graph[closestVertex].nedges; i++) { neighbor = graph[closestVertex].edges[i]; @@ -375,7 +376,7 @@ int dijkstra_sgd(graph_sgd *graph, int source, term_sgd *terms) { float *dists = N_GNEW(graph->n, float); int i; for (i=0; in; i++) { - dists[i] = MAXFLOAT; + dists[i] = FLT_MAX; } dists[source] = 0; for (i=graph->sources[source]; isources[source+1]; i++) { @@ -387,7 +388,7 @@ int dijkstra_sgd(graph_sgd *graph, int source, term_sgd *terms) { int closest = 0, offset = 0; while (extractMax_f(&h, &closest, indices, dists)) { float d = dists[closest]; - if (d == MAXFLOAT) { + if (d == FLT_MAX) { break; } // if the target is fixed then always create a term as shortest paths are not calculated from there -- 2.40.0