[squeak-dev] FloatConstants?

Chris Muller ma.chris.m at gmail.com
Wed Dec 17 18:47:31 UTC 2014


On Wed, Dec 17, 2014 at 11:56 AM, Bert Freudenberg <bert at freudenbergs.de> wrote:
> On 17.12.2014, at 18:17, Chris Muller <asqueaker at gmail.com> wrote:
>>
>>          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..
>
> This is a Float method. You can use the NaN class variable directly.

Thanks.  I thought about that but when I searched the entire 32-bit
space, the ranges

    {(2139095041 to: 2147483647). (4286578689 to: 4294967295)}

reported true for isNaN and, not knowing or caring about Float
representation right now, wasn't sure whether any of those other
values were needed to be nan for optimizing its internal
bit-manipulation..  To be "safe" I decided to use the isNaN message.

But, I guess if that were true then the NaN class-var would be too
dangerous to use, wouldn't it?  So it seems it should be okay to
compare against the class-var..?

I also don't care for the #== comparison, I much prefer #= but that
would be an extra send, is that right?

thanks.


More information about the Squeak-dev mailing list