Skip to content

Commit 125e4fe

Browse files
authored
Merge pull request #35 from thoughtpolice/aseipp/fix-minmax-combine
Fix two bugs in `cbits` relating to distribution values
2 parents fe58b2b + ddd3934 commit 125e4fe

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cbits/distrib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ void hs_distrib_combine(struct distrib* b, struct distrib* a) {
3535
const StgDouble sum_sq_delta = (a->sum_sq_delta + b->sum_sq_delta +
3636
delta * delta * (a->count * b->count) / count);
3737
a->count = count;
38-
a->mean = mean;
38+
a->mean = (count == 0) ? 0.0 : mean; // divide-by-zero gives NaN
3939
a->sum_sq_delta = sum_sq_delta;
4040
a->sum = a->sum + b->sum;
41-
a->min = b->min < a->min ? b->min : a->min;
42-
a->max = b->max > a->max ? b->max : a->max;
41+
a->min = b->min;
42+
a->max = b->max;
4343
hs_unlock(&b->lock);
4444
}

0 commit comments

Comments
 (0)