From: Adam Dickmeiss Date: Wed, 21 Nov 2012 12:04:07 +0000 (+0100) Subject: Minor refactor of r_pos_x X-Git-Tag: v2.0.53~4 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=ce1529fb7ace30ac5b61e1079e5b08fd80f38e5b;ds=sidebyside Minor refactor of r_pos_x Avoiding redundant declarations and division by zero. --- diff --git a/rset/rsmultiandor.c b/rset/rsmultiandor.c index f65039a..be47e2b 100644 --- a/rset/rsmultiandor.c +++ b/rset/rsmultiandor.c @@ -619,14 +619,17 @@ static void r_pos_x(RSFD rfd, double *current, double *total, int and_op) double sum_cur = 0.0; double sum_tot = 0.0; for (i = 0; ino_children; i++){ - double nratio, cur, tot; + double cur, tot; rset_pos(mrfd->items[i].fd, &cur, &tot); yaz_log(log_level, "r_pos: %d %0.1f %0.1f", i, cur,tot); - nratio = cur / tot; if (and_op) { - if (nratio > ratio) - ratio = nratio; + if (tot > 0.0) + { + double nratio = cur / tot; + if (nratio > ratio) + ratio = nratio; + } } else { @@ -635,7 +638,7 @@ static void r_pos_x(RSFD rfd, double *current, double *total, int and_op) sum_tot += tot; } } - if (!and_op) + if (!and_op && sum_tot > 0.0) ratio = sum_cur / sum_tot; if (ratio == 0.0 || ratio == 1.0) { /* nothing there */ *current = 0;