Mantis - Squeak
Viewing Issue Advanced Details
3512 Kernel minor always 04-28-06 01:23 07-14-06 21:19
nicolas cellier  
closed 3.9  
none 3.9  
0003512: Number>>readFrom: does not handle error cases correctly
Number>>readFrom: when encountering a malformed number is not behaving well.

Either it does return 0.
    Number readFrom: ''.
    Number readFrom: 'foo-bar'.
Either it fails when it should not
    Number readFrom: '1e'.
    Number readFrom: '1s'.
Either it succeeds when it should not
    Number readFrom: '--1'.
 Kernel-Number-Parser-Test.1.cs [^] (2,011 bytes) 04-28-06 02:15
 Kernel-Number-SqNumberParserV2.1.cs.gz [^] (3,792 bytes) 05-07-06 21:25

nicolas cellier   
05-07-06 21:24   

i attach a SqNumberParser class that can fix:
- all these weird behaviours
- reading of floating point numbers (round to nearest floating point value)
- reading of -0.0 ( [^] )

First load the two patches correcting:
Integer>>asFloat [^]
and Fraction>>asFloat at [^]

TODO: branch SqNumberParser on Number>>readFrom:
TODO: add a specific NumberParserError or NumberParserException

With the patch, you cannot read '3.e-3' nor '.3e-3' anymore, but these weren't identified as proper squeak syntax...
07-04-06 15:40   
This is faster and better than the current number parsing in class Number. I have provided a cleanup to the current parser in Mantis 0003993, but I really think that this NumberParser is a better approach.

These change sets can be added to the current Squeak image with no impact on the existing parser, so this would be a safe change.
07-14-06 21:19