2011/5/19 Dario Trussardi <[email protected]>:
> 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
>
>
>
>