[squeak-dev] FloatConstants?

David T. Lewis lewis at mail.msen.com
Thu Dec 18 00:04:04 UTC 2014


On Wed, Dec 17, 2014 at 03:22:17PM -0600, Chris Muller wrote:
> > On Wed, Dec 17, 2014 at 11:23 AM, Chris Muller <asqueaker at gmail.com> wrote:
> >>
> >> On Wed, Dec 17, 2014 at 12:55 PM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> >> >
> >> > So am I right in thunking that you want that if the Float has an integer
> >> > equivalent the float and integer have the same hashKey32 and if they don't,
> >> > you don't care as long as the hash is well-distributed?
> >>
> >> No I meant that I need to pickle Floats as an 32-bit Integer,
> >
> > Now I'm really confused.  How come you can get away with 32-bits when Floats
> > are 64-bits?
> 
> Because I need speed and efficiency more than precision.  I'll be
> loading _billions_ of 64-bit Squeak Floats into a indexing system that
> operates on 32-bit integers (it can operate at any size even 256-bit
> but it operates much faster in a 32-bit range due to a lot smaller and
> fewer LargeIntegers and performance takes precedence).

Hi Chris,

A bit off topic but hopefully thinking out of the box:

You have lots of 64-bit Squeak floats. You want to store the values as
32-bit pickles, because the pickle jar can easily store them that way. You
do not care about loss of precision. You do care about storing them efficiently
in some 32-bit system, and you do care about being able to unpickle them back
into Squeak.

So how about using a FloatArray? The primitives already exist to do this
efficiently, so you can store and retrieve Float values (with loss of precision)
to the FloatArray, and you can read and write the pickles with basicAt:
and basicAt:put:.

For example, in a workspace:

    "A float array of 32 bit floats"
    fa := FloatArray new: 10.
    
    "Use at: and put: to store some 64 bit Float values in the array"
    (1 to: 10) do: [:i | fa at: i put: Float pi * i].
    
    "Get the raw 32-bit raw data values of the floats from the array using basicAt:"
    pickles := (1 to: 10) collect: [:i | fa basicAt: i].
    
    "Store the pickles in another FloatArray, demonstrating unpickling with basicAt:put:"
    newFa := FloatArray new: 10.
    (1 to: 10) do: [:i | newFa basicAt: i put: (pickles at: i)].
    
    newFa = fa ==> true

So convert the Float values to pickles using a FloatArray, and store the pickles.

Dave



More information about the Squeak-dev mailing list