Playing with Interval, here is a report and some questions about a
special feature
INTRODUCTION:
------------
Interval on Float are messy.
#do: loops are not consistent with #size nor #at: because of accumulated
round off errors.
This is because inside the do loop we write
aValue := aValue + step
And stop the loop when we reach stop
Things are better if we make things compatible with #at: (index is 0-based)
aValue := start + (index * step)
And stop after self size iterations to be compatible with #size
All this is at
http://bugs.squeak.org/view.php?id=6456It has the advantage of also solving #reverseDo:
http://bugs.squeak.org/view.php?id=6438.
Another related stuff is the way we test for inclusion.
Current implementation try to test inclusion with a fuzzy tolerance.
Unfortunately, it is completely broken and have incorrect patch at
http://bugs.squeak.org/view.php?id=1602 for speeding up indexOf: as
noted by german morales, and better patch by boris gartner at
http://bugs.squeak.org/view.php?id=1603 for correcting both includes:
and indexOf:
The patch is however incomplete because it handles only approximate by
excess, not by default as shown in
http://bugs.squeak.org/view.php?id=6455.
QUESTION:
--------
But why do we test for Float inclusion with fuzzy tolerance in Interval
and not in other collections? And why a fixed tolerance? (1.0e-10
relative to step in original, 1.0e-8 in some correction).
I would tend to implement exactly same behaviour as super and eventually
implement a includes:withTolerance: if needed, in all Collection (though
this is as simple as #detect:, it might be accelerated in Interval if
there is a dedicated selector).
My feeling is that previous implementation of do: and unconsistency with
at: might have motivated the fuzzy test.
But is there another reason to make Interval behave differently from super?
I tend to be cautious now, because when i tried to correct first and
last that incorrectly handle empty Interval
(
http://bugs.squeak.org/view.php?id=6454), it did break the image.
Text selection rely on this behaviour and that is more than 10 messages
to patch.
What is your opinion about the fuzzy inclusion?