stats: Fix off-by-one error in distributions.

bkt size isn't evenly divisible by max-min and it would round down,
it's possible to sample a distribution and have no place to put the sample.
When this case occured the simulator would assert.
This commit is contained in:
Ali Saidi 2010-08-23 11:18:39 -05:00
parent fa01fbddeb
commit 7793773809

View file

@ -2287,7 +2287,7 @@ class Distribution : public DistBase<Distribution, DistStor>
params->min = min;
params->max = max;
params->bucket_size = bkt;
params->buckets = (size_type)rint((max - min + 1.0) / bkt );
params->buckets = (size_type)ceil((max - min + 1.0) / bkt);
this->setParams(params);
this->doInit();
return this->self();
@ -2352,7 +2352,7 @@ class VectorDistribution : public VectorDistBase<VectorDistribution, DistStor>
params->min = min;
params->max = max;
params->bucket_size = bkt;
params->buckets = (size_type)rint((max - min + 1.0) / bkt);
params->buckets = (size_type)ceil((max - min + 1.0) / bkt);
this->setParams(params);
this->doInit(size);
return this->self();