stats: Fix off-by-one error in distributions.
authorAli Saidi <Ali.Saidi@ARM.com>
Mon, 23 Aug 2010 16:18:39 +0000 (11:18 -0500)
committerAli Saidi <Ali.Saidi@ARM.com>
Mon, 23 Aug 2010 16:18:39 +0000 (11:18 -0500)
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.

src/base/statistics.hh

index 8c229d419546f1161de40f585f127a7a2c8b9c38..7eb769e43039bc7e99983b1466800f0d87bfc6f1 100644 (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();