[squeak-dev] The Trunk: Multilingual-ar.87.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Fri Feb 12 08:37:23 UTC 2010


Of course, as indicated by Bert, this make some test fail.
If we follow this road, then we must also remove support for
reading/printing Float in non decimal base.
I personnally agree that this form is mostly educational and has no
major industrial utility.
As squeak is also an educational support, I will let other debate if
this is a major feature or not...

I'm not at all in favour in decomposing operations as you suggested
earlier because this introduces additional round off errors:
| a b |
a := SqNumberParser parse: '3r1.1e55'.
b := (SqNumberParser parse: '3r1.1') * (3 raisedTo: 55).
a - b
-> 3.4359738368e10

If you use current squeak (Number>>#readFrom:) then above forms are equivalent.
This is because (Number>>#readFrom:) use the exact broken
decomposition you suggested.
This decomposition is broken because it does not answer the nearest
Floating point value to the literal expression.

Proof:

3r1.1e55 is literally same as 3r11e54, that is (3+1)*(3 raisedTo: 54).
Of course, this number cannot be represented exactly as a Float, it
has too many digits:
| a |
a := (3+1)*(3 raisedTo: 54).
a highBit - a lowBit
-> 85, that means a 85 bit mantissa is required (plus implied leading
1), Float only has 52 bits (plus implied leading 1)

SqNumberParser does answer a Float nearest the exact literal than
Number>>readFrom:
((SqNumberParser parse: '3r1.1e55') asTrueFraction - ((3r11)*(3
raisedTo: 54))) abs
< ((Number readFrom: '3r1.1e55') asTrueFraction - ((3r11)*(3 raisedTo: 54))) abs
-> true

In fact, the nearest Float, as you can check with predecessor successor.
| a exact |
a := SqNumberParser parse: '3r1.1e55'.
exact := (3r11)*(3 raisedTo: 54).
self assert: (a - exact) abs <= (a successor - exact) abs.
self assert: (a - exact) abs <= (a predecessor - exact) abs.

This of course fail with Number>>readFrom:

You can also simply try
3r1.1e55 - 3r11.0e54
and the SqNumberParser form...
(SqNumberParser parse: '3r1.1e55') - (SqNumberParser parse: '3r11.0e54')

Maybe it's time to push the readFrom: changes i already pushed in Pharo...

Nicolas

2010/2/12  <commits at source.squeak.org>:
> Andreas Raab uploaded a new version of Multilingual to project The Trunk:
> http://source.squeak.org/trunk/Multilingual-ar.87.mcz
>
> ==================== Summary ====================
>
> Name: Multilingual-ar.87
> Author: ar
> Time: 11 February 2010, 11:48:33.736 pm
> UUID: ca61be1a-7e30-2840-9b77-9cc7ecfc2d3f
> Ancestors: Multilingual-ar.86
>
> Change EncodedCharSet>>digitValue: to EncodedCharSet>>digitValueOf:. Part 3/3.
>
> =============== Diff against Multilingual-ar.86 ===============
>
> Item was changed:
>  ----- Method: EncodedCharSet class>>digitValueOf: (in category 'class methods') -----
>  digitValueOf: char
>        "Answer 0-9 if the receiver is $0-$9, 10-35 if it is $A-$Z, and < 0
>        otherwise. This is used to parse literal numbers of radix 2-36."
>
>        | value |
>        value := char charCode.
> +       value <= $9 asciiValue ifTrue:
> +               [^value - $0 asciiValue].
> +       value >= $A asciiValue ifTrue:
> +               [value <= $Z asciiValue ifTrue: [^value - $A asciiValue + 10].
> +                (value >= $a asciiValue and: [value <= $z asciiValue]) ifTrue:
> +                       [^value - $a asciiValue + 10]].
> -       value <= $9 asciiValue
> -               ifTrue: [^value - $0 asciiValue].
> -       value >= $A asciiValue
> -               ifTrue: [value <= $Z asciiValue ifTrue: [^value - $A asciiValue + 10]].
>        ^ -1
>  !
>
> Item was changed:
>  ----- Method: Unicode class>>digitValueOf: (in category 'class methods') -----
>  digitValueOf: char
>        "Answer 0-9 if the receiver is $0-$9, 10-35 if it is $A-$Z, and < 0
>        otherwise. This is used to parse literal numbers of radix 2-36."
>
>        | value |
>        value := char charCode.
> +       value <= $9 asciiValue ifTrue:
> +               [^value - $0 asciiValue].
> +       value >= $A asciiValue ifTrue:
> +               [value <= $Z asciiValue ifTrue: [^value - $A asciiValue + 10].
> +                (value >= $a asciiValue and: [value <= $z asciiValue]) ifTrue:
> +                       [^value - $a asciiValue + 10]].
> -       value <= $9 asciiValue
> -               ifTrue: [^value - $0 asciiValue].
> -       value >= $A asciiValue
> -               ifTrue: [value <= $Z asciiValue ifTrue: [^value - $A asciiValue + 10]].
>
>        value > (DecimalProperty size - 1) ifTrue: [^ -1].
>        ^ (DecimalProperty at: value+1)
>  !
>
> Item was removed:
> - ----- Method: LanguageEnvironment class>>digitValue: (in category 'accessing') -----
> - digitValue: char
> -
> -       ^ Unicode digitValue: char.
> - !
>
> Item was removed:
> - ----- Method: EncodedCharSet class>>digitValue: (in category 'class methods') -----
> - digitValue: char
> -       "Answer 0-9 if the receiver is $0-$9, 10-35 if it is $A-$Z, and < 0
> -       otherwise. This is used to parse literal numbers of radix 2-36."
> -
> -       | value |
> -       value := char charCode.
> -       value <= $9 asciiValue
> -               ifTrue: [^value - $0 asciiValue].
> -       value >= $A asciiValue
> -               ifTrue: [value <= $Z asciiValue ifTrue: [^value - $A asciiValue + 10]].
> -       ^ -1
> - !
>
> Item was removed:
> - ----- Method: Unicode class>>digitValue: (in category 'class methods') -----
> - digitValue: char
> -
> -       | value |
> -       value := char charCode.
> -       value <= $9 asciiValue
> -               ifTrue: [^value - $0 asciiValue].
> -       value >= $A asciiValue
> -               ifTrue: [value <= $Z asciiValue ifTrue: [^value - $A asciiValue + 10]].
> -
> -       value > (DecimalProperty size - 1) ifTrue: [^ -1].
> -       ^ (DecimalProperty at: value+1)
> - !
>
>
>



More information about the Squeak-dev mailing list