Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What are new numbers equal to?

3 views
Skip to first unread message

Brock

unread,
Aug 28, 1986, 1:34:25 PM8/28/86
to

> Reply-To: obr...@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.

0 new messages