In Arrays.qsort the methods Float.compare and Double.compare are used depending on the values in the array. The compare operations perform the following (copied from GNU Classpath):
return isNaN ? 0 : 1;
// recall that 0.0 == -0.0, so we convert to infinites and try again
if (x == 0 && y == 0)
return (int) (1 / x - 1 / y);
if (x == y)
return x > y ? 1 : -1;
In the normal case we're going to hit 6 floating point compares. The case of 0, 0 is common due to using qsort on branch profiles, and this results in 2 divides and 1 subtract. Given we're just comparing to values we should be able to do this substantially cheaper in a VM specific/magic version.