[Pharo-project] Issue 3329 in pharo: Object>>closeTo:

pharo at googlecode.com pharo at googlecode.com
Fri Nov 26 16:33:19 CET 2010

Comment #2 on issue 3329 by alexandre.bergel: Object>>closeTo:

Yeah, I agree. But it is essentially interesting for Float:

Float>>closeTo: num
  	"are these two numbers close?"
	num isNumber ifFalse: [^[self = num] ifError: [false]].
	self = 0.0 ifTrue: [^num abs < 0.0001].
	num = 0 ifTrue: [^self abs < 0.0001].
	^self = num asFloat
		or: [(self - num) abs / (self abs max: num abs) < 0.0001]

The problem is that you can two float which are the same, but have a  
different internal representation.

But still, having closeTo: on Object does not make sense. Does it make  
sense to be able to do 'abc' closeTo: 'abc' ?

More information about the Pharo-project mailing list