[Pharo-project] SIXX problem for ScaledDecimal
Hi, i found some problem into Gemstone relative to SIXX support for manage ScaledDecimal instances. I do some test into Pharo and i found error when i read the sixx declaration relative to ScaledDecimal : <sixx.object sixx.id="0" sixx.type="ScaledDecimal" >123.456s3</sixx.object> For solve this error i define the ScaledDecimal : readSixxContentStringFrom: aStream | numerator scale | numerator := aStream upTo: $s . scale := aStream upToEnd. ^ self newFromNumber: numerator asNumber scale: scale asNumber Now my doubt is relative to string size and performance. A) If i write <sixx.object sixx.id="0" sixx.type="ScaledDecimal" >123.456s3</sixx.object> i have small string in sixx declartion but when create a ScaledDecimal from sixx the system execute the: newFromNumber: aNumber scale: anInteger | aFraction | aFraction := aNumber asFraction. ^aFraction isFraction ifTrue: [self new setNumerator: aFraction numerator denominator: aFraction denominator scale: anInteger] ifFalse: [self new setNumerator: aFraction denominator: 1 scale: anInteger] What is the performance relative to : aFraction := aFloat asFraction. ???? B) The alternative is to write a sixx declaration with: <sixx.object sixx.id="0" sixx.type="ScaledDecimal" >(8687443681197687/70368744177664s3)</sixx.object> in this case the sixx string is big but the ScaledDecimal instance creation is direct: readSixxContentStringFromA: aStream " with numerator and denominator " | numerator denominator scale | aStream next. "skip $(" numerator := aStream upTo: $/ . denominator := aStream upTo: $s. scale := aStream upTo: $). ^ self new setNumerator: numerator asNumber denominator: denominator asNumber scale: scale asNumber Any pointers would be greatly appreciated ! Thanks, Dario
You need to talk with umezawa-sensei about your problem with SIXX On Thu, May 19, 2011 at 3:42 PM, Dario Trussardi <dario.trussardi@tiscali.it> wrote:
Hi,
    i found some problem into Gemstone relative to  SIXX support for manage ScaledDecimal instances.
    I do some test into Pharo and i found error when i read the sixx declaration relative to ScaledDecimal :
        <sixx.object sixx.id="0" sixx.type="ScaledDecimal" >123.456s3</sixx.object>
    For solve this error i define the ScaledDecimal :
        readSixxContentStringFrom: aStream
            | numerator scale |
            numerator := aStream upTo: $s .
            scale := aStream upToEnd.
            ^ self newFromNumber:  numerator asNumber scale: scale asNumber
Now my doubt is relative to string size and performance.
A) Â Â Â If i write
        <sixx.object sixx.id="0" sixx.type="ScaledDecimal" >123.456s3</sixx.object>
    i have small string in sixx declartion but when create a ScaledDecimal from sixx the system execute the:
        newFromNumber: aNumber scale: anInteger             | aFraction |             aFraction := aNumber asFraction.             ^aFraction isFraction             ifTrue: [self new setNumerator: aFraction numerator denominator: aFraction denominator scale: anInteger]             ifFalse: [self new setNumerator: aFraction denominator: 1 scale: anInteger]
    What is the performance relative to :          aFraction := aFloat asFraction.   ????
B) Â Â Â The alternative is to write a sixx declaration with:
        <sixx.object sixx.id="0" sixx.type="ScaledDecimal" >(8687443681197687/70368744177664s3)</sixx.object>
    in this case the sixx string is big but the ScaledDecimal instance creation is direct:
        readSixxContentStringFromA: aStream
            " with numerator and denominator "         | numerator denominator scale |         aStream next. "skip $("         numerator := aStream upTo: $/ .         denominator := aStream upTo: $s.         scale := aStream upTo: $).
        ^ self new setNumerator:  numerator asNumber denominator: denominator asNumber scale:  scale asNumber
Any pointers would be greatly appreciated !
    Thanks,
        Dario
-- Serge Stinckwich UMI UMMISCO 209 (IRD/UPMC), Hanoi, Vietnam Every DSL ends up being Smalltalk http://doesnotunderstand.org/
2011/5/19 Dario Trussardi <dario.trussardi@tiscali.it>:
Hi,
    i found some problem into Gemstone relative to  SIXX support for manage ScaledDecimal instances.
    I do some test into Pharo and i found error when i read the sixx declaration relative to ScaledDecimal :
        <sixx.object sixx.id="0" sixx.type="ScaledDecimal" >123.456s3</sixx.object>
    For solve this error i define the ScaledDecimal :
        readSixxContentStringFrom: aStream
            | numerator scale |
            numerator := aStream upTo: $s .
            scale := aStream upToEnd.
            ^ self newFromNumber:  numerator asNumber scale: scale asNumber
Now my doubt is relative to string size and performance.
A) Â Â Â If i write
        <sixx.object sixx.id="0" sixx.type="ScaledDecimal" >123.456s3</sixx.object>
    i have small string in sixx declartion but when create a ScaledDecimal from sixx the system execute the:
        newFromNumber: aNumber scale: anInteger             | aFraction |             aFraction := aNumber asFraction.             ^aFraction isFraction             ifTrue: [self new setNumerator: aFraction numerator denominator: aFraction denominator scale: anInteger]             ifFalse: [self new setNumerator: aFraction denominator: 1 scale: anInteger]
    What is the performance relative to :          aFraction := aFloat asFraction.   ????
Don't know about sixx, but one thing is sure, you can't use a Float, otherwise you'll loose precision. Float are inexact. In modern Squeak/Pharo you can check this 0.1s1 ~= 0.1. 0.1s1 = (1/10). 0.1 ~= (1/10). Nicolas
B) Â Â Â The alternative is to write a sixx declaration with:
        <sixx.object sixx.id="0" sixx.type="ScaledDecimal" >(8687443681197687/70368744177664s3)</sixx.object>
    in this case the sixx string is big but the ScaledDecimal instance creation is direct:
        readSixxContentStringFromA: aStream
            " with numerator and denominator "         | numerator denominator scale |         aStream next. "skip $("         numerator := aStream upTo: $/ .         denominator := aStream upTo: $s.         scale := aStream upTo: $).
        ^ self new setNumerator:  numerator asNumber denominator: denominator asNumber scale:  scale asNumber
Any pointers would be greatly appreciated !
    Thanks,
        Dario
For ScaledDecimal, SIXX should definite store it as the underlying fraction. Storing it in the printed fashion does change the value of the ScaledDecimal. (1/3) asScaledDecimal: 2 gives 0.33s2 and (33/100) asScaledDecimal: 2 gives 0.33s2 yet 0.33s2 ~= ( (1/3) asScaledDecimal: 2 ) and ( (1/3) asScaledDecimal: 2 ) ~= ( (33/100) asScaledDecimal: 2 ) In other words, the ScaledDecimal is about the precise internal number and the scale to display it - which is NOT the scale that it is stored as. -Chris
participants (4)
-
Chris Cunningham -
Dario Trussardi -
Nicolas Cellier -
Serge Stinckwich