[bug][fix] range of single value gets divide-by-zero exception
Tim Olson
tim at io.com
Sun Nov 14 20:10:20 PST 2004
On Nov 14, 2004, at 7:22 PM, Peter van Rooijen wrote:
> I wonder if the bug is in the fact that a division is done at all in
> such a Range, rather than in using 0 for the stepping value.
Good question. The methods which perform divide (or modulo) by the
step value are:
r@(Range traits) last
r@(Range traits) includes: n
r@(Range traits) size
These appear to be implemented the same way that the Squeak Interval
methods are implemented, and are mainly that way to handle the cases
where (start - end) is not an integral multiple of the step size.
Assuming we want to handle these cases correctly, this appears to be
the cleanest way to do that. Having the step be 0 for Ranges where
start = end leads to a 0/0 singularity which would require special
tests in these methods (and possibly in some new ones which might be
added). Seems best just to handle it during the creation of the Range
by setting the step to a non-zero value.
> Favoring 1 over -1 seems arbitrary in any case.
Yes, although the default step value in the Range prototype is 1, so it
seems good to stick with that.
-- Tim Olson
More information about the Slate
mailing list