Mantis - Squeak
Viewing Issue Advanced Details
3568 Kernel minor always 05-07-06 16:30 09-01-08 18:27
nicolas cellier  
 
normal  
closed 3.9  
fixed  
none    
none 3.10  
0003568: [FIX] Fraction>>asFloat does not answer nearest floating point number
Current implementation can accumulate round off errors.
Comment states that ideally, it should answer nearest floating point number...

I join a test and a patch for this, and round to nearest even according to IEEE 754 default rounding mode.

Patch http://bugs.impara.de/view.php?id=3564 [^] concerning Integer>>asFloat should be applied first, so this one can work correctly.
Fraction need not being reduced for this algorithm to apply.
So, the new asFloat algorithm can be used to convert decimal representations to binary representations (Number readFrom: ), without spending too much time in gcd algorithm...
 Kernel-Number-Fraction-asFloat-Test.1.cs [^] (878 bytes) 05-07-06 17:08
 Kernel-Number-Fraction-asFloat-Patch.2.cs [^] (1,852 bytes) 05-07-06 17:09
 Kernel-Number-Fraction-asFloat-Patch.3.cs [^] (1,877 bytes) 01-10-07 05:33
 Kernel-Number-Fraction-asFloat-Test.2.cs [^] (1,441 bytes) 01-10-07 05:40

Notes
(0005628)
ducasse   
07-08-06 18:01   
in 39 7038
(0008859)
nicolas cellier   
01-10-07 05:25   
Unfortunately, the fix is wrong in one case...

  "test round to nearest even"
  self assert: ((1<<52)+0+(1/2)) asFloat asTrueFraction = ((1<<52)+0).

This was discovered by discussion with Chris Uppal on Dolphin mailing list...
I will send new patch and new tests
(0008861)
nicolas cellier   
01-10-07 05:44   
"fix begin"
Installer mantis bug: 3568 fix: 'Kernel-Number-Fraction-asFloat-Patch.3.cs'.
"fix test"
Installer mantis bug: 3568 fix: 'Kernel-Number-Fraction-asFloat-Test.2.cs'.
"fix end"
(0010486)
edgardec   
04-01-07 13:29   
This now is 7074fix-asFloatanswers.cs and was in updates for 3.10
Thanks Nicolas !
(0012569)
KenCausey   
09-01-08 18:27   
Harvested as update 7074 and released in 3.10-7159