+ assert (max > min);
+
+ {
+ double ul, ll;
+ double lower_tail = modf (min / half_bin_width, &ll);
+ double upper_tail = modf (max / half_bin_width, &ul);
+ lower_limit = ll - 1;
+ upper_limit = ul + 1;
+
+ sparse_end = lower_tail < upper_tail ? -1 : +1;
+ }
+
+ /* The range must be an EVEN number of half bin_widths */
+ if ( (upper_limit - lower_limit) % 2)
+ {
+ /* Extend the range at the end which gives the least unused space */
+ if (sparse_end == +1)
+ lower_limit--;
+ else
+ upper_limit++;
+
+ /* Now the other end has more space */
+ sparse_end *= -1;
+ }
+
+ /* But the range should be aligned to an ODD number of
+ half bin widths, so that the labels are aesthetically pleasing ones. */
+ if ( lower_limit % 2 == 0)
+ {
+ lower_limit += -sparse_end ;
+ upper_limit += -sparse_end ;
+ }
+
+ 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;