I thought i had a method to convert squeak floats to 32 bit little
endian, but apparently it no longer works (if it ever did). Is there an accepted conversion utility/strategy/algorithm for doing this kind of thing? I've got my Second Life client working to the point where an amorphous cloud appears in-world with the correct name-tag, but its probably not facing the right way because I can't send a little-endian float value. Since much of SL is based on 3D coordinates and such, this will be a problem for sure if I try to do anything more sophisticated than floating in mid air as a white cloud (the non-rendering avatar default appearance). Lawson |
I think these two are bigEdian
Float pi asIEEE32BitWord. FloatArray with: Float pi. Nicolas 2010/10/12 Lawson English <[hidden email]>: > I thought i had a method to convert squeak floats to 32 bit little endian, > but apparently it no longer works (if it ever did). > > Is there an accepted conversion utility/strategy/algorithm for doing this > kind of thing? I've got my Second Life client working to the point where an > amorphous cloud appears in-world with the correct name-tag, but its probably > not facing the right way because I can't send a little-endian float value. > Since much of SL is based on 3D coordinates and such, this will be a problem > for sure if I try to do anything more sophisticated than floating in mid air > as a white cloud (the non-rendering avatar default appearance). > > > > Lawson > > > > > |
On 10/12/10 3:29 AM, Nicolas Cellier wrote:
> I think these two are bigEdian > > Float pi asIEEE32BitWord. > FloatArray with: Float pi. > Converts it to a 31-bit int, which is not compatible with swapping endianness because you can't index it. I'm sure I can eventually analyze what the asIEEE32BitWord is doing and put it into a 4 byte array instead of an int, but I was hoping that someone else had already solved the problem. Lawson > 2010/10/12 Lawson English<[hidden email]>: >> I thought i had a method to convert squeak floats to 32 bit little endian, >> but apparently it no longer works (if it ever did). >> >> Is there an accepted conversion utility/strategy/algorithm for doing this >> kind of thing? I've got my Second Life client working to the point where an >> amorphous cloud appears in-world with the correct name-tag, but its probably >> not facing the right way because I can't send a little-endian float value. >> Since much of SL is based on 3D coordinates and such, this will be a problem >> for sure if I try to do anything more sophisticated than floating in mid air >> as a white cloud (the non-rendering avatar default appearance). >> >> >> >> Lawson >> >> >> >> >> > |
On Tue, Oct 12, 2010 at 05:18:40AM -0700, Lawson English wrote:
> On 10/12/10 3:29 AM, Nicolas Cellier wrote: > >I think these two are bigEdian > > > >Float pi asIEEE32BitWord. > >FloatArray with: Float pi. > > > Converts it to a 31-bit int, which is not compatible with swapping > endianness because you can't index it. > > I'm sure I can eventually analyze what the asIEEE32BitWord is doing and > put it into a 4 byte array instead of an int, but I was hoping that > someone else had already solved the problem. > (FloatArray with: Float pi) basicAt: 1 This gives you the value as a LargePositiveInteger. If you are running on a little-endian machine, the value should already be in the byte order you want. If you need to swap bytes (Smalltalk endianness = #big) you can use #bitAnd: and shift operators, etc. Dave |
2010/10/12 David T. Lewis <[hidden email]>:
> On Tue, Oct 12, 2010 at 05:18:40AM -0700, Lawson English wrote: >> On 10/12/10 3:29 AM, Nicolas Cellier wrote: >> >I think these two are bigEdian >> > >> >Float pi asIEEE32BitWord. >> >FloatArray with: Float pi. >> > >> Converts it to a 31-bit int, which is not compatible with swapping >> endianness because you can't index it. >> >> I'm sure I can eventually analyze what the asIEEE32BitWord is doing and >> put it into a 4 byte array instead of an int, but I was hoping that >> someone else had already solved the problem. >> > > (FloatArray with: Float pi) basicAt: 1 > > This gives you the value as a LargePositiveInteger. If you are running > on a little-endian machine, the value should already be in the byte > order you want. If you need to swap bytes (Smalltalk endianness = #big) > you can use #bitAnd: and shift operators, etc. > > Dave > > And to make a ByteArray from an Integer between:0 and: 1<<32-1, you have a license to be hackish: (ByteArray newFrom: (Float pi asIEEE32BitWord + 16r100000000)) copyFrom: 2 to: 5 Nicolas |
2010/10/12 Nicolas Cellier <[hidden email]>:
> 2010/10/12 David T. Lewis <[hidden email]>: >> On Tue, Oct 12, 2010 at 05:18:40AM -0700, Lawson English wrote: >>> On 10/12/10 3:29 AM, Nicolas Cellier wrote: >>> >I think these two are bigEdian >>> > >>> >Float pi asIEEE32BitWord. >>> >FloatArray with: Float pi. >>> > >>> Converts it to a 31-bit int, which is not compatible with swapping >>> endianness because you can't index it. >>> >>> I'm sure I can eventually analyze what the asIEEE32BitWord is doing and >>> put it into a 4 byte array instead of an int, but I was hoping that >>> someone else had already solved the problem. >>> >> >> (FloatArray with: Float pi) basicAt: 1 >> >> This gives you the value as a LargePositiveInteger. If you are running >> on a little-endian machine, the value should already be in the byte >> order you want. If you need to swap bytes (Smalltalk endianness = #big) >> you can use #bitAnd: and shift operators, etc. >> >> Dave >> >> > > And to make a ByteArray from an Integer between:0 and: 1<<32-1, you > have a license to be hackish: > > (ByteArray newFrom: (Float pi asIEEE32BitWord + 16r100000000)) > copyFrom: 2 to: 5 > > Nicolas > Oops no, it's rather (ByteArray newFrom: (Float pi asIEEE32BitWord + 16r100000000)) first: 4 Nicolas |
2010/10/12 Nicolas Cellier <[hidden email]>:
> 2010/10/12 Nicolas Cellier <[hidden email]>: >> 2010/10/12 David T. Lewis <[hidden email]>: >>> On Tue, Oct 12, 2010 at 05:18:40AM -0700, Lawson English wrote: >>>> On 10/12/10 3:29 AM, Nicolas Cellier wrote: >>>> >I think these two are bigEdian >>>> > >>>> >Float pi asIEEE32BitWord. >>>> >FloatArray with: Float pi. >>>> > >>>> Converts it to a 31-bit int, which is not compatible with swapping >>>> endianness because you can't index it. >>>> >>>> I'm sure I can eventually analyze what the asIEEE32BitWord is doing and >>>> put it into a 4 byte array instead of an int, but I was hoping that >>>> someone else had already solved the problem. >>>> >>> >>> (FloatArray with: Float pi) basicAt: 1 >>> >>> This gives you the value as a LargePositiveInteger. If you are running >>> on a little-endian machine, the value should already be in the byte >>> order you want. If you need to swap bytes (Smalltalk endianness = #big) >>> you can use #bitAnd: and shift operators, etc. >>> >>> Dave >>> >>> >> >> And to make a ByteArray from an Integer between:0 and: 1<<32-1, you >> have a license to be hackish: >> >> (ByteArray newFrom: (Float pi asIEEE32BitWord + 16r100000000)) >> copyFrom: 2 to: 5 >> >> Nicolas >> > > Oops no, it's rather > (ByteArray newFrom: (Float pi asIEEE32BitWord + 16r100000000)) first: 4 > > Nicolas > But of course, you don't need to be that hackish (ByteArray new: 4) unsignedLongAt: 1 put: Float pi asIEEE32BitWord bigEndian: false; yourself Nicolas |
Free forum by Nabble | Edit this page |