From 1b88463473da50c2b0259eaf8379de931d618ab4 Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Thu, 31 Jul 2003 08:42:37 +0000 Subject: [PATCH] (is_nonzero): New static function. (check_one_stat): Don't report very small rounding errors when the correct value is 0. --- src/server/stats.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/server/stats.c b/src/server/stats.c index ac79c8511..f328aabf5 100644 --- a/src/server/stats.c +++ b/src/server/stats.c @@ -36,6 +36,8 @@ #include <string.h> #include <stdio.h> #include <setjmp.h> +#include <float.h> +#include <math.h> #include "stats.h" #include "log.h" @@ -292,6 +294,16 @@ update_stat(enum stat_type st, update_one_stat(st, VT_DESCEND, -delta, now); } +static int +is_nonzero(double val) +{ +#ifdef FP_ZERO + return fpclassify(val) != FP_ZERO; +#else + return val >= DBL_MIN || val <= -DBL_MIN; +#endif +} + static int check_one_stat(enum stat_type st, enum value_type vt, @@ -326,12 +338,18 @@ check_one_stat(enum stat_type st, if ((acc < 1 && err > 1e5 * acc) || (acc >= 1 && err / acc > 1e-5)) { - kom_log("Accumulated rounding errors fixed (%s) after" - " %ld updates (st=%d, vt=%d, f=%d, factor=%d): %g => %g\n", - when, - s->updates[f], st, vt, f, factors[f], s->avenrun[f], acc); + /* Don't bother logging assignments to 0. */ + if (is_nonzero(acc) || err > 1e-10) + { + kom_log("Accumulated rounding errors fixed (%s) after" + " %ld updates (st=%d, vt=%d, f=%d, factor=%d):" + " %g => %g\n", + when, + s->updates[f], st, vt, f, factors[f], + s->avenrun[f], acc); + s->updates[f] = 0; + } s->avenrun[f] = acc; - s->updates[f] = 0; changes++; } } -- GitLab