[squeak-dev] FloatConstants?

Louis LaBrunda Lou at Keystone-Software.com
Fri Dec 19 22:01:44 UTC 2014


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]].

Lou


>On Wed, Dec 17, 2014 at 12:20 AM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
>> Hi Chris,
>>
>> On Dec 16, 2014, at 7:24 PM, Chris Muller <asqueaker at gmail.com> wrote:
>>
>>> I wish to access some of the Float constants without a message send.
>>
>> I'm curious.  Why?
>
>Speed.  I need a fast map of the 32-bit Float range to unsigned 32-bit
>integer range such that comparisons within the integer range are
>consistent with comparisons of their floats.  Loosely:
>
>     -Infinity ---------------------- Zero ------------------------
>+Infinity    |   NaN
>          0 ------------------------- (2^31) ----------------------- 2^32
>
>Here is the method I came up with to do this conversion:
>
>          Float>>#hashKey32
>               self == NegativeInfinity ifTrue: [ ^ 0 ].
>               self == Infinity ifTrue: [ ^ 4294967294 ].
>               self isNaN ifTrue: [ ^ 4294967295 ].
>               self == NegativeZero ifTrue:  [ ^ 2147483650 ].
>               "Smallest to largest negative IEEE 32-bit floats range
>from  (2147483649 to: 4286578687), so invert that range."
>               self negative ifTrue: [ ^ (4286578687 - self
>asIEEE32BitWord) + 1 ].
>               "We're positive.  IEEE positives range from (0 to: 2139095039)."
>               ^ self asIEEE32BitWord + 2147483651
>
>Since I need _maximum_ speed, I do not wish the check for Infinites
>and NaN's, the special cases, to require a message send..
>
>>> Would anyone mind if I moved the class-vars defined in Float into a
>>> new Pool called "FloatConstants", so I may import them and write
>>> myFloat == NaN?
>>
>> Instead simply define the pool and initialize it.  IMO it is your own business if you want to define such a pool but it does not need to be in the base image.  The existing access has worked just fine so far.
>
>Since I'm able to put my method within the same scope as the Float
>class-var constants, I guess I don't need the FloatConstants pool
>afterall, but since these are constants that extend beyond the Milky
>Way to the known ends of the physical universe, I can't understand why
>you want access to them restricted to such a tiny bottle.
>FloatConstants would allow better brevity and elegance of code.  Why
>should everyone be required to write "Float pi" over and over instead
>of simply "Pi"?
>
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou at Keystone-Software.com http://www.Keystone-Software.com



More information about the Squeak-dev mailing list