Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003493 [Squeak] Kernel minor always 04-21-06 22:48 01-08-13 21:44
Reporter nicolas cellier View Status public  
Assigned To
Priority normal Resolution open  
Status new   Product Version 3.9
Summary 0003493: printing a float in base 16 is broken sometimes
Description See this example:

    "this should be the maximum floating point value in IEEE 754 double precision"
    (Number readFrom: ((String new: 100) writeStream
        nextPutAll: '2r1.';
        next: 52 put: $1;
        nextPutAll: 'e1023';
        contents)) printStringBase: 16.

"will print as 16r1.0e255"

    (Number readFrom: ((String new: 100) writeStream
        nextPutAll: '2r1.';
        next: 52 put: $1;
        nextPutAll: 'e1020';
        contents)) printStringBase: 16.

"will print as 16r2.0e255, twice the first number when it should be 1/8..."

Additional Information Well, in base (2 raisedTo: Integer anyPositive), printString should be exact...
First number is exactly
    16rF.FFFFFFFFFFFF8e255
and last is exactly
    16r1.FFFFFFFFFFFFFe255
if exponent is written in base 10,
or same mantissa with exponent eFF in base 16...
Note that absPrintExactlyOn:base: will give correct answer.

Rounding should better not be used, because printed number would answer Infinity when read back... But if it where used correctly, then the answers would be:
    16r1.0e256
and
    16r2.0e255

Attached Files  Kernel-Numbers-PrintFloatBase16Patch.1.cs [^] (3,302 bytes) 04-22-06 00:07
 FloatPrintBase16-M3493-Test.1.cs [^] (1,691 bytes) 09-24-07 23:04
 FloatPrintStringBase2-M3493-Test.1.cs [^] (886 bytes) 09-25-07 01:04
 FloatPrintStringBase2-M3493-Test.2.cs [^] (882 bytes) 08-31-08 00:07

- Relationships
related to 0006696assigned andreas ScaledDecimal can read in base 16 but cannot print in base 16 
related to 0006695closed andreas Float storeStringBase: does not store the radix 

- Notes
(0004768 - 797 - 1121 - 1121 - 1121 - 1121 - 1121)
nicolas cellier
04-22-06 00:05

I debugIt, and it is in Float>>absPrintOn:base:

Of course it is Infinity that is striking silently...
As usual, I would prefer an exception and a debugger opened to a silent bug...
Well, there is a protection exp=1023 ifTrue: [...], but 1 line too late...

So i propose a patch, hoping it does not break anything else...
But unfortunately it does not deal with this second bug (not mine):

    (Number readFrom: ((String new: 100) writeStream
        nextPutAll: '2r1.';
        next: 52 put: $1;
        nextPutAll: 'e1023';
        contents)) printStringBase: 2.

    "will answer 2r2.0e1024"

Ouch! tricky tc1 and tc2 logical conditions...
Correct answer would be 2r1.0e1024 if rounding is allowed (but then result cannot be read back, it would overflow and answer Infinity).
 
(0004772 - 27 - 27 - 27 - 27 - 27 - 27)
ducasse
04-22-06 13:38

Could we have some tests :)
 
(0012553 - 104 - 110 - 110 - 110 - 110 - 110)
nicolas cellier
08-31-08 00:07

FloatPrintStringBase2-M3493-Test.1.cs is incorrect.
use FloatPrintStringBase2-M3493-Test.2.cs instead.
 
(0014290 - 763 - 1356 - 1356 - 1356 - 1356 - 1356)
nicolas cellier
01-08-13 21:44

In squeak 4.4, printStringBase: is correct, but the bad behaviour can still be triggered with these snippets:
 
String streamContents: [:str | (Number readFrom: ((String new: 100) writeStream
        nextPutAll: '2r1.';
        next: 52 put: $1;
        nextPutAll: 'e1023';
        contents)) absPrintOn: str base: 16].

String streamContents: [:str | (Number readFrom: ((String new: 100) writeStream
        nextPutAll: '2r1.';
        next: 52 put: $1;
        nextPutAll: 'e1023';
        contents)) absPrintOn: str base: 16].

String streamContents: [:str | (Number readFrom: ((String new: 100) writeStream
        nextPutAll: '2r1.';
        next: 52 put: $1;
        nextPutAll: 'e1023';
        contents)) absPrintOn: str base: 2].
 

- Issue History
Date Modified Username Field Change
04-21-06 22:48 nicolas cellier New Issue
04-22-06 00:05 nicolas cellier Note Added: 0004768
04-22-06 00:07 nicolas cellier File Added: Kernel-Numbers-PrintFloatBase16Patch.1.cs
04-22-06 13:38 ducasse Note Added: 0004772
09-24-07 23:04 nicolas cellier File Added: FloatPrintBase16-M3493-Test.1.cs
09-25-07 01:04 nicolas cellier File Added: FloatPrintStringBase2-M3493-Test.1.cs
09-25-07 01:16 matthewf Relationship added related to 0006696
09-25-07 01:18 matthewf Relationship added related to 0006695
08-31-08 00:07 nicolas cellier File Added: FloatPrintStringBase2-M3493-Test.2.cs
08-31-08 00:07 nicolas cellier Note Added: 0012553
01-08-13 21:44 nicolas cellier Note Added: 0014290


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
63 total queries executed.
39 unique queries executed.
Powered by Mantis Bugtracker