+ /* If there are any completely empty bins, then remove them,
+ since empty bins don't really add much information to the histogram.
+ */
+ if (upper_slack > 2 * half_bin_width)
+ {
+ upper_slack -= 2 * half_bin_width;
+ upper_limit -=2;
+ }
+
+ if (lower_slack >= 2 * half_bin_width)
+ {
+ lower_slack -= 2 * half_bin_width;
+ lower_limit +=2;
+ }
+
+ *adj_min = lower_limit * half_bin_width;
+ *adj_max = upper_limit * half_bin_width;
+
+ testing_assert (*adj_max > max);
+ testing_assert (*adj_min <= min);
+
+ return (upper_limit - lower_limit) / 2.0;
+}
+
+
+
+struct histogram *
+histogram_create (double bin_width_in, double min, double max)
+{
+ struct decimal bin_width;
+ const int MAX_BINS = 25;
+ struct histogram *h;
+ struct statistic *stat;
+ int bins;
+ double adjusted_min, adjusted_max;
+
+ if (max == min)
+ {
+ msg (MW, _("Not creating histogram because the data contains less than 2 distinct values"));
+ return NULL;
+ }
+
+ assert (bin_width_in > 0);