PackageDescription: SYSBUG-asRational


SYSBUG -as Rational

Last published: February 6, 2006 by 'nice'

Defines 0 Classes
Extends 2 Classes


This is a patch for a very bad bug : converting Double to Fraction to Double loose bits...

These ones give a result different from 0 before you load this parcel :
(2**52+1.0d0/(2**55)) asRational asDouble - (2**52+1.0d0/(2**55))
(2**23+1.0e0/(2**26)) asRational asFloat - (2**23+1.0e0/(2**26))
After you load this parcel you can still test old methods saved as asRationalSuper :
(2**52+1.0d0/(2**55)) asRationalSuper asDouble - (2**52+1.0d0/(2**55))
(2**23+1.0e0/(2**26)) asRationalSuper asFloat - (2**23+1.0e0/(2**26))

Due to this bug, in Visualworks release 2.5, some Fraction and Double or Float could answer true to =, but have different hash codes.
This side effect has been removed in VW release 3.0, because hash code of LimitedPrecisionReal is no more computed using asRational.
But the main bug still survive...

Another bug is miss-handling of IEEE gradual underflow - try this :
1.0d-313 asRational
This will fail before you load this parcel

Other advantages of loading this parcel :
- shorter Fraction (try Double pi asRational)
- faster algorithm try :

| d |
d := Double pi.
Time millisecondsToRun: [1000 timesRepeat: [d asRationalSuper]].
Time millisecondsToRun: [1000 timesRepeat: [d asRational]].

| d |
d := 23.47d.
Time millisecondsToRun: [1000 timesRepeat: [d asRationalSuper]].
Time millisecondsToRun: [1000 timesRepeat: [d asRational]].

| d |
d := 1/2.0d.
Time millisecondsToRun: [1000 timesRepeat: [d asRationalSuper]].
Time millisecondsToRun: [1000 timesRepeat: [d asRational]].