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=6456 It 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?
2007/4/30, nicolas cellier ncellier@ifrance.com:
What is your opinion about the fuzzy inclusion?
You are probably the only expert for that domain :-)
Damien Cassou a écrit :
2007/4/30, nicolas cellier ncellier@ifrance.com:
What is your opinion about the fuzzy inclusion?
You are probably the only expert for that domain :-)
Very kind. I hope not. Squeak floats were written well before i ever got interested in. My job is limited to some polishing.
And my question is about thoughts behind current implementation and eventual use in some application, both beyond my expertise.
That's a general problem in Squeak (and sure in other open source projects): - why this implementation ? - why this feature ? It's not written in the code, as legible as it can be. It could eventually be in SUnit TestCase with good comments. Unfortunately, the answer is often only in the mind of few persons. But i don't want to open a thread on documentation again...
Nicolas
squeak-dev@lists.squeakfoundation.org