Floating point exceptions

Joachim Durchholz joachim.durchholz at munich.netsurf.de
Tue Mar 23 06:25:06 UTC 1999


"Michael S. Klein" wrote:
> 
> The upside is that if you get an exact number, you dont have to worry
> about things like round-off errors.  Think how nice it is to have
> Fractions where
> 
>         (4 / 3 * 3) = 4

Agreed.

> One could extend the realm of exact representations so that
> 
>         5 sqrt squared = 5

You cannot. Equality is undecidable for irrational numbers (and not even
if you limit yourself to algebraic numbers). Ramanujan once published
equalities of irrational numbers that took the mathematic community
years to prove (Ramanujan just intuited them, and he was right in most
if not all cases even though he couldn't prove or disprove them
himself). They had surprisingly simple forms, similar to
            ____________
           / ___    ___
   ___    V V 4  + V 5
  v 3  = ----------------
               2

(I can't remember an exact equation, so the above is just an
illustration of the complexity of the Ramanujan equations).

Of course, if you're better prepared to live with a
possibly-noncanonical formula instead of an inprecise number, you can
always build a small symbolic math package. In cases just as Morphic, a
sensible architecture would be to just build up the formulae (possibly
simplifying them as far as possible with minimal effort to prevent them
from becoming unwieldy), and convert them to floating-point numbers or
rationals as soon as a numeric value is needed (e.g. to test two
positions for pixel-wise coincidence, or to paint the thing on the
screen).
Of course one could reuse the formula simplification mechanisms to build
an entire symbolic math framework on top of it. Just make sure that
formula simplification doesn't take up too much time when the thing is
used in Morphic (i.e. Morphic must have a way to specify that the more
costly simplifications aren't tried).

Regards,
Joachim
-- 
Please don't send unsolicited ads.





More information about the Squeak-dev mailing list