harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Rogers <ian.rog...@manchester.ac.uk>
Subject Re: Float/Double comparison performance
Date Fri, 08 May 2009 13:42:30 GMT
2009/5/8 Tim Ellison <t.p.ellison@gmail.com>:
> Egor Pasko wrote:
>>  Ian Rogers wrote:
>>> - is it worth specializing the code in Arrays.lessThan to something
>>> like (I don't think Jikes RVM can inline compareTo and achieve an
>>> equivalent transformation and it saves quite a number of compares):
>>>
>>>     private static boolean lessThan(float float1, float float2) {
>>>         // Non-zero, non-NaN checking.
>>>         if (float2 > float1) {
>>>             return true;
>>>         }
>>>         if (float1 >= float2 && 0.0f != float1) {
>>>             return false;
>>>         }
>
> For correctness, this got committed as
>  +        if (float1 >= float2 && (0.0f != float1 || 0.0f != float2))
{
>  +            return false;
>  +        }
>
> The problem is that if you pass in float1 or float2 == +/-0.0 (which
> Roger is apparently doing regularly) then it will fall through to the
> slow rawintbits computation.

Roger? Thanks for the fix :-)

>>>         // NaNs are equal to other NaNs and larger than any other float
>>>         if (isNaN(float1)) {
>>>             return false;
>>>         } else if (isNaN(float2)) {
>>>             return true;
>>>         }
>>>         // Deal with +0.0 and -0.0
>>>         int f1 = floatToRawIntBits(float1);
>>>         int f2 = floatToRawIntBits(float2);
>>>         return f1 < f2;
>>>     }
>
> I think it would be better to separate out the > and == tests, i.e.:
> -        if (float1 >= float2 && (0.0f != float1 || 0.0f != float2)) {
> +        if (float1 > float2) {
>             return false;
>         }
> +        if (float1 == float2 && 0.0f != float1) {
> +            return false;
> +        }
>
> WDYT?

I agree :-)

Regards,
Ian

Mime
View raw message