Mantis - Squeak
Viewing Issue Advanced Details
6982 Kernel minor always 03-14-08 22:31 04-18-10 21:58
nicolas cellier  
nicolas cellier  
normal  
closed 3.10  
fixed  
none    
none trunk  
0006982: Number>>readFrom: does not handle many digits correctly
It incorrectly answer an Infinity or even a NaN in some cases:

| s1 s2 |
s1 := '0.' , (String new: 320 withAll: $0) , '1e321'.
s2 := '1' , (String new: 321 withAll: $0) , '.0e321'.
self assert: (Number readFrom: s1) = 1.
self assert: (Number readFrom: s2) = 1.
  "First is Infinity, second is NaN..."
self assert: (SqNumberParser readFrom: s1) = 1.
self assert: (SqNumberParser readFrom: s2) = 1.

It seems it would be time to connect SqNumberParser...
Beside, SqNumberParser answer nearest Float.
 Float-readFromManyDigits-Test-M6982-nice.1.cs [^] (786 bytes) 03-15-08 00:06
 Float-readFromManyDigits-Patch-M6982-nice.1.cs [^] (6,067 bytes) 03-15-08 00:11
 Float-initialize-Patch-M6982-nice.1.cs [^] (1,570 bytes) 03-15-08 21:55
 Float-readFromManyDigits-Patch-M6982-nice.2.cs [^] (4,571 bytes) 08-31-08 00:33

Notes
(0011922)
nicolas cellier   
03-14-08 22:34   
Hem, i'm just bad at copy/paste game... correct test is below:


| s1 s2 |
s1 := '1' , (String new: 321 withAll: $0) , '.0e-321'.
s2 := '0.' , (String new: 320 withAll: $0) , '1e321'.
self assert: (Number readFrom: s1) = 1.
self assert: (Number readFrom: s2) = 1.
self assert: (SqNumberParser parse: s1) = 1.
self assert: (SqNumberParser parse: s2) = 1.
(0011925)
nicolas cellier   
03-15-08 00:16   
Beware, the patch is not compatible with the old behaviour of answering 0 when there is no digit. It raise an Error instead.

Use (Number readFrom aStream ifFail: [0]) explicitely if interested in this feature.

See also 0003512 0006779 0006976 0003712
(0011928)
nicolas cellier   
03-15-08 21:56   
If Number readFrom: is modified to use SqNumberParser,
then the constant used to initialize MaxVal is too high,
and leads to an Infinity if recompiled.

So here comes patch Float-initialize-Patch-M6982-nice.1.cs
new and old values are respectively:

    MaxVal _ 1.7976931348623157e308.
    MaxVal _ 1.7976931348623159e308.
(0012163)
nicolas cellier   
05-25-08 18:38   
"fix begin"
Installer mantis bug: 6982 fix:'Float-readFromManyDigits-Patch-M6982-nice.1.cs'.
Installer mantis bug: 6982 fix:'Float-initialize-Patch-M6982-nice.1.cs'.
"fix test"
Installer mantis bug: 6982 fix:'Float-readFromManyDigits-Test-M6982-nice.1.cs'.
"fix end"
(0012543)
nicolas cellier   
08-29-08 20:13   
"fix begin"
Installer mantis ensureFix: 7169.
Installer mantis bug: 6982 fix:'Float-readFromManyDigits-Patch-M6982-nice.1.cs'.
Installer mantis bug: 6982 fix:'Float-initialize-Patch-M6982-nice.2.cs'.
"fix test"
Installer mantis bug: 6982 fix:'Float-readFromManyDigits-Test-M6982-nice.1.cs'.
"fix end"

(0012554)
nicolas cellier   
08-31-08 00:36   
There was a stupid bug
    instVar = ...
instead of
    instVar := ...
in Float-readFromManyDigits-Patch-M6982-nice.1.cs

Rather use Float-readFromManyDigits-Patch-M6982-nice.2.cs instead.

He, the leftArrow would be welcome to avoid this kind of typo.
(0013509)
nicolas cellier   
02-13-10 02:06   
in http://source.squeak.org/trunk/Kernel-nice.396.mcz [^]
and http://source.squeak.org/trunk/KernelTests-nice.131.mcz [^]