Quantcast

[VM-dev] How serialize/materialize SmallFloat64?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[VM-dev] How serialize/materialize SmallFloat64?

Denis Kudriashov
 
I tested my serialization library on 64bits image and tests for floats are failed. 
For boxed floats I use #basicNew. And SmallFloat signal error 'SmallFloat64s can only be created by performing arithmetic'

So question how implement smallfloat serialization/materialization ?
 
Do we have something similar to ByteArray>>asInteger and SmallInteger>>asByteArray?

Best regards,
Denis
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [VM-dev] How serialize/materialize SmallFloat64?

Bert Freudenberg
 
On Wed, Apr 12, 2017 at 5:25 PM, Denis Kudriashov <[hidden email]> wrote:
 
I tested my serialization library on 64bits image and tests for floats are failed. 
For boxed floats I use #basicNew. And SmallFloat signal error 'SmallFloat64s can only be created by performing arithmetic'

So question how implement smallfloat serialization/materialization ?

SmallFloats still support word access via basicAt:

| a x y |
x := 0.5.
a := {x at: 1. x at: 2}.
y := BoxedFloat64 new.
y at: 1 put: (a at: 1).
y at: 2 put: (a at: 2).
y := y * 1.0.
{x. x class. a. y. y class} {0.5 . SmallFloat64 . #(1071644672 0) . 0.5 . SmallFloat64}

So to serialize you just use the words. And to deserialize you just create a BoxedFloat. If you want to normalize the boxed float you do some arithmetic operation on it. But boxed floats work fine for any value, it's just a space optimization.

- Bert -

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [VM-dev] How serialize/materialize SmallFloat64?

Denis Kudriashov
 

2017-04-12 17:42 GMT+02:00 Bert Freudenberg <[hidden email]>:
SmallFloats still support word access via basicAt:

| a x y |
x := 0.5.
a := {x at: 1. x at: 2}.
y := BoxedFloat64 new.
y at: 1 put: (a at: 1).
y at: 2 put: (a at: 2).
y := y * 1.0.
{x. x class. a. y. y class} {0.5 . SmallFloat64 . #(1071644672 0) . 0.5 . SmallFloat64}

So to serialize you just use the words. And to deserialize you just create a BoxedFloat. If you want to normalize the boxed float you do some arithmetic operation on it. But boxed floats work fine for any value, it's just a space optimization.

Nice trick. Thank's
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [VM-dev] How serialize/materialize SmallFloat64?

Eliot Miranda-2
In reply to this post by Bert Freudenberg
 

On Apr 12, 2017, at 8:42 AM, Bert Freudenberg <[hidden email]> wrote:

On Wed, Apr 12, 2017 at 5:25 PM, Denis Kudriashov <[hidden email]> wrote:
 
I tested my serialization library on 64bits image and tests for floats are failed. 
For boxed floats I use #basicNew. And SmallFloat signal error 'SmallFloat64s can only be created by performing arithmetic'

So question how implement smallfloat serialization/materialization ?

SmallFloats still support word access via basicAt:

| a x y |
x := 0.5.
a := {x at: 1. x at: 2}.
y := BoxedFloat64 new.
y at: 1 put: (a at: 1).
y at: 2 put: (a at: 2).
y := y * 1.0.
{x. x class. a. y. y class} {0.5 . SmallFloat64 . #(1071644672 0) . 0.5 . SmallFloat64}

So to serialize you just use the words. And to deserialize you just create a BoxedFloat. If you want to normalize the boxed float you do some arithmetic operation on it. But boxed floats work fine for any value, it's just a space optimization.

and time ;-)

- Bert -
Loading...