ANSI, =, hash, Integer, Float

Stephan Rudlof sr at evolgo.de
Tue Dec 17 12:21:55 UTC 2002


Richard A. O'Keefe wrote:
> Colin Putney <cputney at whistler.com> wrote:
> 	Here's another proposal: make Float>>= call #shouldNotImplement.
> 	
> 	I wonder what, if anything, it would break?
> 	
> Well, for one thing, it would leave 0 = 0.0 true,
> and ANSI requires that (x = y) implies (y = x).
> 
> Equality is perfectly well defined for IEEE floating point arithmetic.
> Unlike C, Smalltalk specifies the grouping of message sends, so if you
> have a Smalltalk layered atop an IEEE arithmetic, there is no question
> about when two Floats should be equal and when they should not.
> 
> It isn't equality between floating point numbers that's the problem.
> It's equality between floating point numbers and rational numbers.
> Prolog solved the problem by recognising that
>     "X is the same key as Y" (=)
> and "X and Y are pretty much the same number" (=:=)
> are different relations, so that 0 = 0, 0.0 = 0.0, -0.0 = -0.0
> are all true, 0 = 0.0, 0.0 = -0.0, -0.0 = 0 are all false,
> and 0 =:= 0.0, 0.0 =:= -0.0, -0.0 =:= 0 are all true.
> 
> 
> 

What about
- defining #= true and #hash equal
  applied to numerical equal rational numbers
  (SmallInteger, LargePositiveInteger, LargeNegativeInteger, Fraction)
and
- defining #= as undefined (raising an Exception)
  for comparisons of all these rationals with Floats
  (also if numerical equal)?

This would avoid the trap of making loops with bad end conditions like e.g.

| anInteger |
anInteger := 0.
[self doSomething. anInteger := anInteger + 0.1]
  whileTrue: [anInteger <= 1.0]

which may work or may not work as expected (don't know without trying it).


Would such a change break something?


Greetings,

Stephan
-- 
Stephan Rudlof (sr at evolgo.de)
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3




More information about the Squeak-dev mailing list