[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] BUG gst2.2: Float asExactFraction broken
From: |
nicolas cellier |
Subject: |
[Help-smalltalk] BUG gst2.2: Float asExactFraction broken |
Date: |
Sat, 27 Jan 2007 03:45:50 +0100 |
User-agent: |
Thunderbird 1.5.0.4 (X11/20060516) |
Hi,
just try 1.0d-20 asExactFraction.
Float>>asExactFraction implementation will evaluate:
(1.0d-20 timesTwoPower: 1.0d-20 exponent + 1.0d-20 class precision)
truncated /
(1 bitShift: 1.0d-20 exponent + 1.0d-20 class precision)
That is 0/0
I guess mantissa is rather
self timesTwoPower: self exponent negated + self class precision
Then, sign of self exponent negated + self class precision should be
discussed in order to avoid division by zero...
I propose this implementation:
| shift mantissa |
self checkCoercion.
shift := self exponent negated + self class precision.
mantissa := (self timesTwoPower: shift) truncated.
^shift negative
ifTrue: [mantissa * (1 bitShift: shift negated)]
ifFalse: [mantissa / (1 bitShift: shift)]
Nicolas Cellier
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-smalltalk] BUG gst2.2: Float asExactFraction broken,
nicolas cellier <=