Fraction equality and Float infinity problem

ncellier@ifrance.com ncellier at ifrance.com
Tue Mar 28 13:25:46 UTC 2006


Well, the problem is not only for infinity (Overflow).

It is also true for underflow.
  (2/(11 raisedTo: 400)) = 0.0. "is true"
  (2/(11 raisedTo: 400)) = 0. "is false"

And in fact, the equality transitivity problem can show up for any fraction not exactly representable in IEEE Floating point, that is most Fractions.

Since Fraction set is dense in set of real numbers, i can find an infinite number of Fractions lying between two Float. Since IEEE floating point arithmetic only have a finite number of possible values, then for each floating point value, there exist an infinite number of fractions that will be equal to this float (in current implementation, not mathematically), but the fraction will not equal to each other, thanks to exact arithmetic.

Example:
  | a b |
  a := (16rFFFFFFFFFFFFF11 / 16r1000000000000000).
  b := (16rFFFFFFFFFFFFF10 / 16r1000000000000000).
  c := a asFloat.
  {a = b.
  a = c.
  b = c.}. "is {false . true . true}"

Knowing this, i'am not sure that ((1/3) asFloat = (1/3)) should answer true. Maybe that should be only the case for exact representation like 1/2 1/4 3/4 etc...

But in this case, we also have to redefine coercion to coercing to Fraction instead of Float, because Fraction are more general (yes, Float is a subset of Fraction).

If we do not coerce to exact arithmetic, we will have ((1/3) asFloat - (1/3)) isZero, and still we might be caught by some form of equality problem...

Thus are we ready to exchange our fast floating point algorithm for slower Fraction, with a huge number of useless digits, each time somebody introduce a Fraction.
Are we really sure we vote for this perfect system ?
I am not sure at all.

And that is also the case between floating points and integers.
Sure other dialects also have the equality problem, maybe not for Infinity, but for less trivial inexact arithmetic case.

All is coming from problem of these languages calling floating point numbers real. Real is more general than fraction, ah yes, we have been foolished by this one.

What should we do ?

What is your opinion ?
 
________________________________________________________________________
iFRANCE, exprimez-vous !
http://web.ifrance.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20060328/0d9a1cd5/attachment.htm


More information about the Squeak-dev mailing list