Shouldn't 2 hash = 2.0 hash? [LONG]

David N. Smith (IBM) dnsmith at watson.ibm.com
Wed Dec 1 23:28:05 UTC 1999


At 14:19 -0500 12/1/99, Jan Theodore Galkowski wrote:
>On Mon, 29 Nov 1999 16:26:34   David N. Smith (IBM) wrote:
>...SNIP...
>>
>>I'd argue that having (2.0 = 2) answer false is better than forcing
>>the hashes to be equal. Besides, comparing floats is a sin one should
>>not encourage. I'd rather see #= answer false and that some other
>>method be used for 'has equivalent value'.
>
>[snip]
>
>I'm not sure this is a better answer than
>David's, but from a numerical standpoint
>there is a lot of justification in
>defining
>
>     2.0 = 2.0 --> false
>
>or any two flonums.  This is because the
>only way that flonums can be considered
>"equal" is by specifying a context dependent
>tolerance, as
>
>     ((a - b) abs) < tol
>
>where tol is some multiple of machine
>epsilon.

Floating-point numbers can be compared for equality according to the 
IEEE standard (which virtually all modern machines use). They are 
equal if they have the same value and sign, excepting that +0.0 and 
-0.0 are considered equal.

It's usually considered bad form to compare for equality, but 
sometimes numerical analysts use it. For example, the standard test 
for machine precision involves an iteration that stops on an equal 
test.

Thus, (1.0 = 1.0) should answer true.

Also note that if not, one could have the case where:

    1.0 = 1.0  =>  false

but

    1.0 == 1.0 =>  true!

'Tis best not to mess around with mother nature...  :)

Dave
_______________________________
David N. Smith
IBM T J Watson Research Center
Hawthorne, NY
_______________________________
Any opinions or recommendations
herein are those of the author
and not of his employer.





More information about the Squeak-dev mailing list