From a0b0ffb38287336c2ebdc629956d3ced64dc12d5 Mon Sep 17 00:00:00 2001 From: Friedrich Beckmann Date: Tue, 16 Feb 2016 10:30:32 +0100 Subject: [PATCH] histogram - added another upper bin to include cases which have max values This fixes the problem that cases which have values exactly at the upper bin limit of the upper bin are not included in the binning. The fix is based on the idea from John to just add another bin when the bin limit is just equal to the maximum case value. --- src/math/histogram.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/math/histogram.c b/src/math/histogram.c index 60adaa92d1..8aaa16f9e0 100644 --- a/src/math/histogram.c +++ b/src/math/histogram.c @@ -119,6 +119,15 @@ hist_find_pretty_no_of_bins(double bin_width_in, double min, double max, nbins = ceil((max-*adjusted_min)/binwidth); *adjusted_max = nbins*binwidth + *adjusted_min; + /* adjusted_max should never be smaller than max but if it is equal + then the gsl_histogram will not add the cases which have max value */ + if (*adjusted_max <= max) + { + *adjusted_max += binwidth; + nbins++; + } + assert (*adjusted_min <= min); + return nbins; } -- 2.30.2