From: John Darrington Date: Sun, 25 Mar 2012 08:47:27 +0000 (+0200) Subject: Histograms: Put hard limit on the number of histogram bins X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d532977937c51fd8d08fdabe57e06af4b05a8ed0;p=pspp Histograms: Put hard limit on the number of histogram bins Histograms with less than one bin are not useful (and tend to cause crashes!) Histograms with very large numbers of bins are also of little use, and cause other implementation headaches. --- diff --git a/src/math/histogram.c b/src/math/histogram.c index 2f19f31095..5441df6bbc 100644 --- a/src/math/histogram.c +++ b/src/math/histogram.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2004, 2008, 2009, 2011 Free Software Foundation, Inc. + Copyright (C) 2004, 2008, 2009, 2011, 2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,8 +40,6 @@ histogram_add (struct histogram *h, double y, double c) stat->accumulate (stat, NULL, c, 0, y); } - - static void acc (struct statistic *s, const struct ccase *cx UNUSED, double c, double cc UNUSED, double y) { @@ -50,7 +48,6 @@ acc (struct statistic *s, const struct ccase *cx UNUSED, double c, double cc UNU gsl_histogram_accumulate (hist->gsl_hist, y, c); } - static void destroy (struct statistic *s) { @@ -114,6 +111,13 @@ histogram_create (double bin_width, double min, double max) bins = (upper_limit - lower_limit) / 2.0; + /* Force the number of bins to lie in a sensible range */ + if (bins > 25) + bins = 25; + + if (bins < 1) + bins = 1; + upper_limit *= half_bin_width; lower_limit *= half_bin_width;