[squeak-dev] FloatConstants?
Levente Uzonyi
leves at elte.hu
Sun Dec 21 03:27:59 UTC 2014
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
|