Implementing isFinite by looking at the exponent field would avoid the creation of a transient floating point number.
On 12/21/14 13:11 , Eliot Miranda wrote:
Hi Levente,
please rewrite using a temp to hold the raw bits, a class var to hold the float array and hexadecimal. Then one can understand much easier. Also is inlining isFinite that important for performance?
rawBits := FloatArrayBuffer at: 1 put: self; basicAt: 1 etc...
Eliot (phone hence not writing the full method)
On Dec 20, 2014, at 7:27 PM, Levente Uzonyi leves@elte.hu wrote:
On Sat, 20 Dec 2014, Chris Muller wrote:
On Fri, Dec 19, 2014 at 4:01 PM, Louis LaBrunda Lou@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