[Glass] Floats problem with SIXX between Pharo and GemStone

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Glass] Floats problem with SIXX between Pharo and GemStone

Mariano Martinez Peck
Hi guys,

When I export SmallDoubles with SIXX in GemStone it generates something like this:

<sixx.object sixx.id="15" sixx.name="close" sixx.type="SmallDouble" >1.0000000000000000E-02</sixx.object>

This is because "0.01 asString" -> '1.0000000000000000E-02'

Then I want to load this in Pharo. So first problem is that of course SmallDouble doesn't exist. So I did:

aSixxShapeChangeStream shapeChangers at: #SmallDouble put: Float.
But then, SIXX use Float >> readFrom: aStream
"Answer a new Float as described on the stream, aStream." ^(super readFrom: aStream) asFloat


So, of course " Float readFrom: '1.0000000000000000E-02'  "  ->  1.0

So my 0.01 in gemstone become 1.0 in Pharo....

Am I doing something wrong or this is expected? What is the best workaround?

In GemStone I could print the SmallDouble in the XML with a method like

Float >> xmlRepresentation
^ String streamContents:
[:strm | self printOn: strm base: 10]

Is this the correct approach? If true, I guess I should define:

Float >> sixxContentOn: aStream indent: level context: dictionary aStream nextPutAll: self xmlRepresentation


Thoughts?

Thanks in advance,

--
Mariano
http://marianopeck.wordpress.com

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Floats problem with SIXX between Pharo and GemStone

Martin McClure-5
On 02/26/2014 01:38 PM, Mariano Martinez Peck wrote:
>
> So, of course " Float readFrom: '1.0000000000000000E-02'  "  ->  1.0

This is because Pharo only accepts lower-case letters for exponent ($e
$d $q). So if you replace E with e Pharo will parse it as you wish.

-Martin

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Floats problem with SIXX between Pharo and GemStone

Masashi UMEZAWA-2
In reply to this post by Mariano Martinez Peck
Hi Mariano,

How about just defining:

SmallDouble >> sixxType
  ^'Float'

SmallDouble >> sixxWriteValue
  ^self asFloat

I'm not using GemStone right now, so maybe my assumption would be
inaccurate. But just a quick answer.

Regards,

2014-02-27 6:38 GMT+09:00 Mariano Martinez Peck <[hidden email]>:

> Hi guys,
>
> When I export SmallDoubles with SIXX in GemStone it generates something like
> this:
>
> <sixx.object sixx.id="15" sixx.name="close" sixx.type="SmallDouble"
>>1.0000000000000000E-02</sixx.object>
>
> This is because "0.01 asString" -> '1.0000000000000000E-02'
>
> Then I want to load this in Pharo. So first problem is that of course
> SmallDouble doesn't exist. So I did:
>
> aSixxShapeChangeStream shapeChangers at: #SmallDouble put: Float.
> But then, SIXX use Float >> readFrom: aStream
> "Answer a new Float as described on the stream, aStream." ^(super readFrom:
> aStream) asFloat
>
>
> So, of course " Float readFrom: '1.0000000000000000E-02'  "  ->  1.0
>
> So my 0.01 in gemstone become 1.0 in Pharo....
>
> Am I doing something wrong or this is expected? What is the best workaround?
>
> In GemStone I could print the SmallDouble in the XML with a method like
>
> Float >> xmlRepresentation
> ^ String streamContents:
> [:strm | self printOn: strm base: 10]
>
> Is this the correct approach? If true, I guess I should define:
>
> Float >> sixxContentOn: aStream indent: level context: dictionary aStream
> nextPutAll: self xmlRepresentation
>
>
> Thoughts?
>
> Thanks in advance,
>
> --
> Mariano
> http://marianopeck.wordpress.com



--
[:masashi | ^umezawa]
_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Floats problem with SIXX between Pharo and GemStone

Mariano Martinez Peck
In reply to this post by Martin McClure-5



On Wed, Feb 26, 2014 at 7:25 PM, Martin McClure <[hidden email]> wrote:
On 02/26/2014 01:38 PM, Mariano Martinez Peck wrote:
>
> So, of course " Float readFrom: '1.0000000000000000E-02'  "  ->  1.0

This is because Pharo only accepts lower-case letters for exponent ($e
$d $q). So if you replace E with e Pharo will parse it as you wish.


Thanks all.  I took this solution as the simples workaround. I overriden this method in my Pharo image:

SqNumberPasrser>>exponentLetters
   "current comment"
   ^'edqEDQ'


Now...a similar question is....is there a way to move Floats between Pharo and GemStone with SIXX without loosing decimals (no rounded)?
Sixx in Pharo exports Floats doing #printString. So for example:

5645.0000000000000000000000000786786 printString
-> '5645.0'

I loose info. So what is the alternative? 

Thanks,


--
Mariano
http://marianopeck.wordpress.com

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Floats problem with SIXX between Pharo and GemStone

Martin McClure-5
On 03/03/2014 07:14 AM, Mariano Martinez Peck wrote:
>
> Now...a similar question is....is there a way to move Floats between
> Pharo and GemStone with SIXX *without *loosing decimals (no rounded)?
> Sixx in Pharo exports Floats doing #printString. So for example:
>
> 5645.0000000000000000000000000786786 printString
> -> '5645.0'
>
> I loose info. So what is the alternative?

In this example, there is no information lost. Most rational numbers are
not exactly representable as Floats.
5645.0000000000000000000000000786786 is one of those. 5645.0 is the
closest number representable as a Float, so this is a correct,
information-preserving representation.

Regards,

-Martin
_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass