Hello,

I realised that in the current implementation, when a number is serialised by 
STON it is either as an integer literal or as a float literal.

There is a risk to loose precision, especially if what you serialise is a 
ScaledDecimal or a fraction.

I propose a simple change to fix this:

1. Add STONWriter>>#isInJsonMode method which returns true if the STONWriter 
wants to write JSON

2. Add:

Fraction>>#stonOn: stonWriter
    stonWriter isInJsonMode
        ifTrue: [ ^ super stonOn: stonWriter ].
    
    stonWriter writeObject: self streamMap: [ :dictionary |
        dictionary at: #numerator put: numerator.
        dictionary at: #denominator put: denominator ]

3. Add:

ScaledDecimal>>#stonOn: stonWriter
    stonWriter isInJsonMode
        ifTrue: [ ^ super stonOn: stonWriter ].
    
    stonWriter writeObject: self streamMap: [ :dictionary |
        dictionary at: #numerator put: numerator.
        dictionary at: #denominator put: denominator.
        dictionary at: #scale put: scale ]


This change has a main drawback, storing fractions and scaled decimal will 
result in a huge overhead.

Maybe for ScaledDecimal we can use Pharo’s literal (e.g. 1.12s2).

For fractions I don’t know what literal could be used?

Or maybe the overhead is fine?

Cheers,

Julien

---
Julien Delplanque
Doctorant à l’Université de Lille
http://juliendelplanque.be/phd.html
Equipe Rmod, Inria
Bâtiment B 40, Avenue Halley 59650 Villeneuve d'Ascq
Numéro de téléphone: +333 59 35 86 40

Reply via email to