Fun with Number readFrom: What should we do ?

nicolas cellier ncellier at ifrance.com
Fri Apr 28 18:08:12 UTC 2006


Le Vendredi 28 Avril 2006 18:27, francisco.j.garau at jpmorgan.com a écrit :
> Andreas,
>
> I completely agree with what you said except for the first sentence. Why
> do you think it is a "complete and utter overkill"? I can think of three
> possibilities:
>
> 1) The extra class you are adding to the image (SqNumberParser)
> 2) The extra object involved in the parsing
> 3) All the explicit methods that you have to define on the SqNumberParser
> object.
>
> None of them seems an overkill to me. I am obviously missing something.
>
> Cheers,
> Francisco
>

I added the bug report and a few test cases at 
http://bugs.impara.de/view.php?id=3512 last night.

I have a first implementation of SqNumberParser.
It is more convenient to have a class than a set of messages (see how many are 
necessary in Number>>readFrom:), because we can store some intermediate 
results and better optimize Float reading (number of trailing zeroes is an 
example that can save useless computations). Relax, creating a class does not 
spoil efficiency.

The second advantage of SqNumberParser is that it is a good starting point for 
those wanting their own extension for Number parsing as suggested by Diego 
and Francisco.
The class could easily have other extensions like indicating the error in the 
TextEditor, like for code...

So far, i suppressed the bugs i know, and the class read Integer ScaledDecimal 
and Float (including nan infinity and negative zero), and pass all the 
NumberParsingTests successfully.

However i still have the bellerophon algorithm (from tony's reference) failing 
with last bit incorrect in a few cases (i can check that with asTrueFraction 
for number greater than 1.0 timestwoPower: 53). So i do not release it yet.

Float>>absPrintOnExactly;base: works rather well and is a good candidate for 
testing readFrom:. However, i do not over trust it, because it includes the 
same code that bugged absPrintOn: (See note in 
http://bugs.impara.de/view.php?id=3493) : it adds 1 to a digit without 
testing if digit=(base-9)... I did not reveal the bug yet.

Nicolas




More information about the Squeak-dev mailing list