Floats to Bytes and back again

Travis or Kerrin Griggs tkc at bmi.net
Sat Oct 31 17:16:59 UTC 1998

Dan Ingalls wrote:

> >I'm trying to create a typed FloatArray. There's not a lot in the system
> >for converting floats to bytes, so I hacked up something where I use
> >basicAt: to extract the first and second dwords, and then strip the
> >dwords down a byte at a time (a bit more complex then VW where
> >changeClassToThatOf: #[] works handily). But now that I've got it ripped
> >down into 8 bytes, I can't figure out how to get the float back again. I
> >put the 4 byte chunks back together (via bitShift: and +), but can't use
> >basicAt:put: on an instance of a float. Feature, bug,...? Is there a
> >better way to do this anyway?
> >
> >Travis Griggs
> I bet you forgot to use Float new: 2 instead of just Float new (which defaults to new: 1).  [This should probably be fixed]
> Try the following example:
>          | r |
>         r := Float new: 2.
>         r basicAt: 1 put: (Float pi basicAt: 1).
>         r basicAt: 2 put: (Float pi basicAt: 2).
>         r

Yup. That was it. Actually I used Float basicNew which made it's size 0. Thanks much!

Travis Griggs

More information about the Squeak-dev mailing list