From 77937738096e227ebfe5bd2fb999c35032c2c8c4 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 23 Aug 2010 11:18:39 -0500 Subject: 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. --- src/base/statistics.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 8c229d419..7eb769e43 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -2287,7 +2287,7 @@ class Distribution : public DistBase 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 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(); -- cgit v1.2.3