infinity comparison

lex at cc.gatech.edu lex at cc.gatech.edu
Fri Sep 24 22:15:36 UTC 2004


"David T. Lewis" <lewis at mail.msen.com> wrote:
> On Sun, Sep 19, 2004 at 07:27:03PM -0400, Lex Spoon wrote:
> > 
> > It does appear that we have to favor one semantics or the other.  [-1.0
> > sqrt] has to evaluate either to [Complex i] or to [NaN], which in turn
> > have to be different values.  Keystroke for keystroke, I'd guess that
> > for Smalltalk, sloppy intuitive arithmetic, where you'd prefer [Complex
> > i], is much more common than carefully tuned Floating point arithmetic,
> > so I'd guess we want to make [-1.0 sqrt] be [Complex i].
> 
> How about:
>   -1.0 sqrt ==> Complex i
>   Complex i asFloat ==> NaN
> 
> Thus:
>   -1.0 sqrt asFloat ==> NaN
> 


Interesting.  So if you want IEEE semantics you have to do asFloat after
everything?  That might be sufficient; I can't tell for sure.  I suspect
there may be a corner case floating around that does not behave the
same, though.

Note that you can't just do asFloat at the end, because of things like
this:

	(-1.0 sqrt)  -  (-1.0 sqrt) 
	
Normal IEEE floating point would give you NaN as the answer, but an
image with complex numbers would give you 0.  Sending asFloat to that
would still give you 0.  This matters because NaN is not just a way to
say the answer is inexpressible; it can also be used to say that one of
the intermediate computations had an inexpressible result.  If you
reliably want IEEE semantics, you have to do asFloat after every
computation (unless you can somehow prove it is still a valid float in
particular cases).


I have no feeling for whether it would be convenient.  It strikes me as
a little annoying for the IEEE people, but I'm not sure how much that
matters.  It certainly IS convenient for unthinking Squeak users who
just start doing some arithmetic.  A bad part is that it is very easy to
leave out the asFloat's by accident; it would be nice if the IEEE people
can pay the annoyance up front somehow and not have to be quite so
careful, e.g. if they had to type. in 1.5ieee instead of just 1.5. 
Though that of course opens the door to occasionally typing 1.5 by
accident, which is a similar error.

I don't see any real happy answers here, but it still seems least bad to
have people do [1.5ieee] or [1.5 asIEEEFloat] whenever they input number
literals.  Then, operations between IEEEFloat instances can all follow
the IEEE rules, while happy Float instances do things like coercing to
Complex whenever necessary.  I don't know in this case what to do about
mixed arithmetic between IEEE and non-IEEE floats; does the answer come
out as an IEEEFloat or a HappySqueakFloat?  


-Lex



More information about the Squeak-dev mailing list