+static
+double get_slack (double limit, double half_bin_width, int *n_half_bins)
+{
+ double ipart, remainder;
+
+ assert (half_bin_width > 0);
+
+ remainder = modf (limit / half_bin_width, &ipart);
+
+ /* In C modf and % behave in an unexpected (to me at any rate) manner
+ when presented with a negative value
+
+ For example, modf (-7.0 / 3.0) returns -2.0 R -0.3333
+ */
+
+
+ *n_half_bins = ipart;
+
+ return remainder * half_bin_width;
+}
+
+
+/* This functions adjusts the upper and lower range of the histogram to make them fit BIN_WIDTH
+ MIN and MAX are the lowest and highest data to be plotted in the histogram.
+ ADJ_MIN and ADJ_MAX are locations of the adjusted values of MIN and MAX (the range will
+ always be equal or slightly larger).
+ Returns the number of bins.
+
+ The "testing_assert" expressions in this function should be algebraically correct.
+ However, due to floating point rounding they could fail, especially when small numbers
+ are involved. In normal use, therefore, testing_assert does nothing.
+ */
+static int
+adjust_bin_ranges (double bin_width, double min, double max, double *adj_min, double *adj_max)