'From Squeak3.10beta of 22 July 2007 [latest update: #7159] on 31 August 2008 at 3:14:34 am'!
"Change Set: SqNumberParser_speedUp_Patch_M6976_nice
Date: 31 August 2008
Author: nice
The speed up I provided for http://bugs.squeak.org/view.php?id=6976
introduces a little bug:
some gradual underflow are read one bit off, and SqNumberParser fails to anwser nearest Floating point value due to a bad test in step 3 of speed improvement
3) hack (aRadix raisedTo: exponent) with base 2 bitShift: arithmetic
and use timesTwoPower: a posteriori to avoid some LargePositiveInteger.
Here is a patch"!
!SqNumberParser methodsFor: 'parsing-private' stamp: 'nice 8/31/2008 03:14'!
makeFloatFromMantissa: m exponent: k base: aRadix
"Convert infinite precision arithmetic into Floating point.
This alogrithm rely on correct IEEE rounding mode
being implemented in Integer>>asFloat and Fraction>>asFloat"
| p den |
p := aRadix lowBit - 1.
^k positive
ifTrue: [(m * (((aRadix bitShift: p negated) raisedToInteger: k))) asFloat timesTwoPower: p*k]
ifFalse: [
den := (aRadix bitShift: p negated) raisedToInteger: k negated.
(m highBit - den highBit between: -1021 - (p*k) and: 1023)
ifTrue: ["There is no gradual underflow, do the arithmetic with fewest bits"
(Fraction numerator: m denominator: den) asFloat timesTwoPower: p*k]
ifFalse: ["There is some gradual underflow or overflow, do full bits arithmetic"
(Fraction numerator: m denominator: (den bitShift: p*k negated)) asFloat]]! !