harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Egor Pasko <egor.pa...@gmail.com>
Subject Re: Float/Double comparison performance
Date Wed, 06 May 2009 08:08:23 GMT
On the 0x5A7 day of Apache Harmony Ian Rogers wrote:
> 2009/5/4 Egor Pasko <egor.pasko@gmail.com>:
>> On the 0x5A5 day of Apache Harmony Tim Ellison wrote:
>>> Dan Bornstein wrote:
>>>> On Fri, May 1, 2009 at 4:33 AM, Egor Pasko <egor.pasko@gmail.com> wrote:
>>>>> // Non-zero and non-NaN equality checking.
>>>>> if (float1 == float2 && (0.0f != float1 || 0.0f != float2)) {
>>>>>  return 0;
>>>>> }
>>>>
>>>> Would the following be a useful and safe improvement over the above?:
>>>>
>>>>     if (float1 == float2 && 0.0f != (float1 + float2)) {
>>>>
>>>> I think this would save at least one test and branch. I'm not an
>>>> IEEE754 expert, but I think that, given that the two floats are ==,
>>>> the second test could only be true if they are both zeroes.
>>>
>>> In fact, since you have the ==, why is it not sufficient to say
>>>
>>> (float1 == float2 && 0.0f != float1)
>>>
>>> Discuss :-)
>>
>> agreed!
>>
>> --
>> Egor Pasko
>>
>>
>
> Also agreed with everything above :-) One final thing is that the
> final comparisons of == and < could be replaced with (NB.
> -Integer.MIN_VALUE == Integer.MIN_VALUE):
>
> return (f1 >> 32) - (f2 >> 32)
>
> does anyone have a performance feeling about that?

If by 32 you mean 31 I have a correctness feeling in addition :)

-- 
Egor Pasko


Mime
View raw message