[bug] my first squeak bugfix - Interval>>includes:

Peter Smet peter.smet at flinders.edu.au
Fri Jul 30 06:16:03 UTC 1999


Alan,

I was having a look at a similar fix when you posted your code.
I think it may not always work due to the nature of \\ and floating
point precision/rounding. Here are some anomalies:
(1 to: 5 by: 1) includes: 1.4           -- is true, but should be false
(1.3 to: 2.2 by: 0.3) includes: 1.9  -- is false but should be true
 (1 to: 5 by: 0.2) includes: 1.2
(1 to: 5 by: 0.3) includes: 1.3
both (incorrectly) evaluate to false...

Peter



-----Original Message-----
From: Alan Lovejoy <sourcery at pacbell.net>
To: Randal L. Schwartz <merlyn at stonehenge.com>; squeak at cs.uiuc.edu
<squeak at cs.uiuc.edu>
Date: Friday, July 30, 1999 3:24 PM
Subject: re: [bug] my first squeak bugfix - Interval>>includes:


>> ** Original Sender: merlyn at stonehenge.com (Randal L. Schwartz)
>>
>> Interval>>includes: fails if the increment is not 1.  Here's code that
works:
>>
>> includes: aNumber
>>   ^self increment = 1
>>     ifTrue: [aNumber between: self first and: self last]
>>     ifFalse: [super includes: aNumber] "fall back to enumerate items"
>>
>
>Oh dear.  The ParcPlace code for Interval>includes: has worked since I
first
>started using it, way back in 1986.  So I was shocked to see the following
code
>in my Squeak image:
>
>Interval>includes: aNumber
> ^ aNumber between: self first and: self last
>
>I guess this reinforces for me yet again that I should not assume that
>things that have always been working correctly in the ParcPlace
>image line are also good in Squeak (in spite of the fact that they both
>ultimately come from Xerox PARC stock).
>
>As for the fix above, it will work, but I would like to offer an
alternative:
>
>Interval>includes: aNumber
> ^ (aNumber between: self first and: self last)
> and: [self increment = 1
> ifTrue: [true]
> ifFalse: [aNumber - self first \\ self increment = 0]]
>
>Kudos to Randy for finding this!
>
>--Alan
>





More information about the Squeak-dev mailing list