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. >> // 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? Regards, Tim