Intervals
Jarvis, Robert P.
Jarvisb at timken.com
Tue Nov 30 20:50:57 UTC 1999
> -----Original Message-----
> From: David N. Smith (IBM) [SMTP:dnsmith at watson.ibm.com]
> Sent: Tuesday, November 30, 1999 2:45 PM
> To: squeak at cs.uiuc.edu
> Subject: RE: Intervals
>
> I do think that #includes:, if allowed for an interval, should answer
> true for all values that 'anInterval asArray' includes (or, the
> equivalent, the set values passed to a #do: block) and false for
> others. This is not unreasonable and someone else today posted a
> solution (the same method that's in Collection).
>
> However, it cannot be done with a simple computation. Fudge factors
> can only make it look right for your test cases. Try this interval
> with your code:
>
> (1.0e-200 to: 5.0e-200 by: 1.0e-200) asArray
> => (1.0e-200 2.0e-200 3.0e-200 4.0e-200 5.0e-200 )
>
> Aren't floats fun! :-)
>
OK. Incorporating Michael Donegan's version of Interval>>valuesInclude:
(thanks, Michael), and taking into account Peter Crowther's suggestion to
scale the fudge factor by the step value (thanks, Peter), we get the
following change set:
'From Squeak2.6 of 11 October 1999 [latest update: #1559] on 30 November
1999 at 3:32:28 pm'!
!Interval methodsFor: 'accessing' stamp: 'rpj 11/30/1999 11:04'!
includes: aNumber
"Determine if aNumber is an element of this interval."
^(self rangeIncludes: aNumber) and: [ self valuesInclude: aNumber ]!
!
!Interval methodsFor: 'private' stamp: 'rpj 11/30/1999 15:29'!
rangeIncludes: aNumber
"Private"
^aNumber between: (self first min: self last) and: (self first max:
self last)! !
!Interval methodsFor: 'private' stamp: 'rpj 11/30/1999 15:22'!
valuesInclude: aNumber
"Private - answer whether or not aNumber is one of the enumerated
values in this interval."
| val |
val _ aNumber - self first / self increment.
^(val - val rounded) abs < (step * 1e-10)
! !
Given this, David, is the problem you observed with the
(1.0e-200 to: 5.0e-200 by: 1.0e-200)
interval now taken care of? I'm not seeing any unusual behavior, i.e.
#includes: answers true where I'd expect it and false where I'd expect it
(for the values I tested).
Bob Jarvis
Compuware @ Timken
More information about the Squeak-dev
mailing list
|