[squeak-dev] FloatConstants?

Chris Muller asqueaker at gmail.com
Sun Dec 21 19:04:26 UTC 2014


Oh wow, thanks for clarifying that!  I missed what Dave was trying to
say.  Now I see he meant for me to use FloatArray _as_ the 64-bit -->
32-bit conversion tool, with (basicAt: 1) providing the 32-bit
Integer.  Thank you for spelling that out!



On Sat, Dec 20, 2014 at 9:27 PM, Levente Uzonyi <leves at elte.hu> wrote:
> On Sat, 20 Dec 2014, Chris Muller wrote:
>
>> On Fri, Dec 19, 2014 at 4:01 PM, Louis LaBrunda
>> <Lou at keystone-software.com> wrote:
>>>
>>> Hi Chris,
>>>
>>> Is this any faster?
>>>
>>> Float>>#hashKey32
>>>
>>> ^self isFinite ifTrue: [
>>>         self negative ifTrue: [4286578688 - self asIEEE32BitWord]
>>> ifFalse: [self
>>> asIEEE32BitWord + 2147483651]
>>> ] ifFalse: [self negative ifTrue: [0] ifFalse: [4294967294]].
>>
>>
>> About the same, but I think I like your code better.  Thanks.
>
>
> Dave has already suggested to use a FloatArray for conversion instead of
> #asIEEE32BitWord. We use this technique in various network protocol
> implementations, and it works great.
>
> Here's a significantly faster, optimized version:
>
> hashKey32: aFloatArray
>
>         self - self = 0.0 ifTrue: [
>                 self < 0.0 ifTrue: [ ^4286578688 - (aFloatArray at: 1 put:
> self; basicAt: 1) ].
>                 ^2147483651 + (aFloatArray at: 1 put: self; basicAt: 1) ].
>         self < 0.0 ifTrue: [ ^0 ].
>         ^4294967294
>
> The argument is any FloatArray instance with at least one slot.
>
>
> Levente
>
>>
>>
>


More information about the Squeak-dev mailing list