fcmpg 0x96

Compares two floats and pushes -1, 0 or 1; NaN gives 1.

Opcode
0x96 (150)
Family
Comparisons
Operands
none
Length
1 byte
Operand stack
…, value1 (float), value2 (float) → …, result (int)
Can throw
nothing at run time (beyond linking errors)
Spec name
fcmp<op>

What it does

Compares two floats: pushes 1 if the first is greater, 0 if equal, -1 if less. If either is NaN, it pushes 1; that is the only difference between fcmpl and fcmpg.

javac picks whichever makes a comparison with NaN false. For a < b or a <= b it uses fcmpg: NaN gives 1, the branch past the then-part is taken, and the condition is false. For a > b and a >= b it uses fcmpl, where NaN gives -1.

How often javac uses it

In JDK 25.0.5's java.base module, fcmpg appears 59 times in 12 of its 7,391 classes: <0.01% of all instructions, the 165th most common of 194 opcodes in use. Some of the methods that use it: java.lang.Float.toHexString, java.lang.Math.min, java.nio.FloatBuffer.compare, java.util.Arrays.binarySearch0.

Example

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; fcmpg is highlighted.

static boolean floatLess(float a, float b) in Compare, compiled by javac 25
8return a < b;
0fload_0 // a
1fload_1 // b

Open in the viewer

Related instructions

fcmpl Compares two floats and pushes -1, 0 or 1; NaN gives -1.lcmp Compares two longs and pushes -1, 0 or 1.dcmpl Compares two doubles and pushes -1, 0 or 1; NaN gives -1.

Specification: JVMS §6.5, fcmp<op> (Java SE 25).