What javac does
Comparing longs, floats and doubles
A compare instruction pushes -1, 0 or 1; then an ordinary int branch.
There is no "branch if long less than". Comparing longs, floats or doubles takes two instructions: a compare that pushes -1, 0 or 1, then an int branch on the result.
The source
// Comparing longs, floats and doubles: a compare instruction first, then an int branch.
public class Compare {
static boolean longLess(long a, long b) {
return a < b;
}
static boolean floatLess(float a, float b) {
return a < b;
}
static boolean doubleGreater(double a, double b) {
return a > b;
}
}Compiled by javac 25 with -g and --release 8 to 25. Where releases produce different bytecode, each version is shown.
What to look for
longLessislcmp, thenifgeto the false result.floatLessusesfcmpganddoubleGreaterusesdcmpl. The two forms differ only in what NaN gives, and javac picks the one that makes any comparison with NaN false.