From a056732695cac7f3c0b79a127edfdf0023ccd537 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 25 Jul 2016 10:39:02 +0200 Subject: [PATCH] yet another == with doubles shouldn't we use std::numeric_limits infinity and has_infinity instead of this DBL_MAX that is sooooo C-style? --- src/surf/AsFloyd.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/surf/AsFloyd.cpp b/src/surf/AsFloyd.cpp index 7949cf271e..8c835e51e4 100644 --- a/src/surf/AsFloyd.cpp +++ b/src/surf/AsFloyd.cpp @@ -26,13 +26,12 @@ AsFloyd::AsFloyd(const char*name) } AsFloyd::~AsFloyd(){ - int i, j; - int table_size = (int)xbt_dynar_length(vertices_); + int table_size = static_cast(xbt_dynar_length(vertices_)); if (linkTable_ == nullptr) // Dealing with a parse error in the file? return; /* Delete link_table */ - for (i = 0; i < table_size; i++) - for (j = 0; j < table_size; j++) + for (int i = 0; i < table_size; i++) + for (int j = 0; j < table_size; j++) routing_route_free(TO_FLOYD_LINK(i, j)); xbt_free(linkTable_); @@ -85,7 +84,7 @@ void AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbar void AsFloyd::addRoute(sg_platf_route_cbarg_t route) { /* set the size of table routing */ - int table_size = (int)xbt_dynar_length(vertices_); + int table_size = static_cast(xbt_dynar_length(vertices_)); addRouteCheckParams(route); @@ -187,11 +186,9 @@ void AsFloyd::seal(){ for (unsigned int a = 0; a < table_size; a++) { for (unsigned int b = 0; b < table_size; b++) { if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) { - if (TO_FLOYD_COST(a, b) == DBL_MAX || - (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) < - TO_FLOYD_COST(a, b))) { - TO_FLOYD_COST(a, b) = - TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b); + if (fabs(TO_FLOYD_COST(a, b) - DBL_MAX) < std::numeric_limits::epsilon() || + (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) < TO_FLOYD_COST(a, b))) { + TO_FLOYD_COST(a, b) = TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b); TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b); } } -- 2.20.1