From acbb6a5bebd11b6c741b0b9ce1b6eb75f4cee61f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 8 Feb 2015 16:26:48 +0000 Subject: [PATCH] check for nan --- src/ats/plugin_ats_ril.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index 047be865c..cd867b95c 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c @@ -477,23 +477,20 @@ struct GAS_RIL_Handle */ static double agent_q (struct RIL_Peer_Agent *agent, - const double *state, int action) + const double *state, + int action) { - int i; - double result = 0; + unsigned int i; + double result = 0.0; for (i = 0; i < agent->m; i++) - { result += state[i] * agent->W[action][i]; - } - GNUNET_assert(!isnan(result)); - - //prevent crash when learning diverges + /* prevent crashes if learning diverges */ + if (isnan(result)) + return isnan(result) * UINT32_MAX; if (isinf(result)) - { return isinf(result) * UINT32_MAX; - } return result; } -- 2.25.1