[net.lang.st80] What are new numbers equal to?

obrien@randvax.UUCP (Michael O'Brien) (08/27/86)

For reasons perhaps better left unexplained, I recently evaluated the expression
"Float new = 0.0".  Hmm.  Should it be true?  False?  What value is in there,
anyway?  "nil" isn't a number.  Is it still "nil"?

BS II, of course, stepped off the curb.  Ran itself out of space contemplating
the philosophical wonderfulness of it all.  Dolphin CV4 claimed it was "true",
which is probably worse.  The same question, of course, applies to
"Integer new = 0", which also sends BS II out to lunch.
Note that class SmallInteger evades the problem by overriding the message "new"
and screaming at the user via a notifier.

Now, no one in his right mind ever creates numbers this way, but the philosophical
question remains, and it sure seems to me as if Smalltalkers are not, in general,
shy of philosophical questions.

Comments?
-- 
Mike O'Brien
The Rand Corporation

{sdcrdcf,decvax}!randvax!obrien
obrien@rand-unix.arpa

allenw@tekchips.UUCP (Brock) (08/28/86)

>  Reply-To: obrien@randvax.UUCP (Michael O'Brien)
>  Organization: Rand Corp., Santa Monica
>  
>  For reasons perhaps better left unexplained, I recently evaluated the expression
>  "Float new = 0.0".  Hmm.  Should it be true?  False?  What value is in there,
>  anyway?  "nil" isn't a number.  Is it still "nil"?

Tektronix implementations return false.  Why?  A Float is a word indexable object
with 2 indexable fields.  Such an object can be validly created by the expression:
	Float new: 2.  "The fields of this object are initialized to binary 0
			by the virtual machine"

Since the binary representation of 0.0 is 32 bits of binary 0's
(Float new: 2) = 0.0  should return true.

Now, Float new (using the definition of new inherited from Object) produces a
word indexable object with NO fields.  Sending = to a Float invokes a primitive
method.  In our implementations, the primitive does not notice that the receiving
Float does not have any fields (instances of primitive classes ARE NOT SUPPOSED
to be malformed).  Thus it acesses the non-existant fields which are really part
of the next object in memory.  Since it is very unlikely that the accessed value
will consists of 32-bits of 0's the comparsion result is false.

Class Float  could over-ride the definition of new as follows:

	new
	   "Return a new instance of class float initialized to 0.0"
	^self basicNew: 2  "Floats always have 2 indexable fields"

Alternatively, if the implementation (such as Tek's) support full IEEE floating
point arithmetic including not-a-numbers then Float new could initialize the
instance to a NaN.  I will explore this for incorporation into our next release.

>                           The same question, of course, applies to
> "Integer new = 0", which also sends BS II out to lunch.

Class Integer is an ABSTRACT CLASS.  This means that it is not intended to have
any instances.  Integer new = 0 results in an infinate recursion within the
generic comparsion code code defined in Integer and Magnitude.

Perhaps if class Integer was named AbstractInteger there would be less
chance of this type of error occuring.


	Allen Wirfs-Brock
	Computer Research Lab.
	Tektronix, Inc.