Intervals

Jarvis, Robert P. Jarvisb at timken.com
Tue Nov 30 16:21:02 UTC 1999


> -----Original Message-----
> From:	Peter Crowther [SMTP:Peter.Crowther at IT-IQ.com]
> Sent:	Tuesday, November 30, 1999 9:25 AM
> To:	'squeak at cs.uiuc.edu'
> Subject:	RE: Intervals
> 
> You're still assuming steps at, or of the order of, 1.
> 
<sigh>  Guilty as charged.  I also confess to having missed an edge
condition.  Dare I hope for a velvet rope with which to be hung, m'lud?  :-)

'From Squeak2.6 of 11 October 1999 [latest update: #1559] on 30 November
1999 at 11:07:18 am'!

!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 11:01'!
rangeIncludes: aNumber
	"Private"
	^aNumber between: (self first min: self last) and: (self first max:
self last)! !

!Interval methodsFor: 'private' stamp: 'rpj 11/30/1999 11:04'!
valuesInclude: aNumber
	"Private - answer whether or not aNumber is one of the enumerated
values in this interval."
	^(aNumber - self first \\ step = 0) or: [ ((aNumber - self first \\
step - step) abs < (step * 1e-10) abs) or: [ (aNumber - self first \\ step)
abs < (step * 1e-10) abs ] ]! !

I know the addition of a fudge factor may cause problems in some cases, but
it does (help) Squeak support Dan's Principle of Least Astonishment.  To me
it's quite amazing that Squeak says

	(1.0 to: 20.0 by: 0.2) includes: 1.2 ==> false

while it's (a bit) less amazing for it to say

	(1.0 to: 20.0 by: 0.2) includes: 19.999999999999 ==> true

Of course, all this mucking about with Floats is going to come back to haunt
us at some later date.  Floats, as I think I've mentioned in the past, are
evil...

Bob Jarvis
Compuware @ Timken





More information about the Squeak-dev mailing list