dcmpl 0x97

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

Opcode
0x97 (151)
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, dcmpl appears 162 times in 39 of its 7,391 classes: <0.01% of all instructions, the 147th most common of 194 opcodes in use. Some of the methods that use it: java.lang.classfile.CodeBuilder.loadConstant, java.lang.Double.toHexString, java.lang.FdLibm$Asin.compute, java.lang.FdLibm$Atan.compute.

Example

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

static boolean doubleGreater(double a, double b) in Compare, compiled by javac 25
12return a > b;
0dload_0 // a
1dload_2 // b

Open in the viewer

Related instructions

dcmpg 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).