dcmpg 0x98

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

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

What it does

Compares two doubles: 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 dcmpl and dcmpg.

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

How often javac uses it

In JDK 25.0.5's java.base module, dcmpg appears 92 times in 21 of its 7,391 classes: <0.01% of all instructions, the 158th most common of 194 opcodes in use. Some of the methods that use it: java.lang.Double.toHexString, java.lang.FdLibm$Cbrt.compute, java.lang.FdLibm$Exp.compute, java.lang.FdLibm$Expm1.compute.

Related instructions

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

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