---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 24 Edition"
java_version: 24
chapter: "Chapter 6. The Java Virtual Machine Instruction Set"
section: "6.5.dcmp_op"
heading: "dcmp<op>"
parent: "6.5. Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se24/html/jvms-6.html#jvms-6.5.dcmp_op
id: "6.5.dcmp_op"
url: https://jvm.obfuscated.software/jvms/se24/6.5.dcmp_op.html
raw: https://jvm.obfuscated.software/jvms/se24/6.5.dcmp_op.md
---

# dcmp\<op>

## Operation

Compare `double`

## Format

```
dcmp<op>
```

## Forms

*dcmpg* = 152 (0x98)

*dcmpl* = 151 (0x97)

## Operand Stack

..., *value1*, *value2* →

..., *result*

## Description

Both *value1* and *value2* must be of type `double`. The values are popped from the operand stack and a floating-point comparison is performed:

- If *value1* is greater than *value2*, the `int` value 1 is pushed onto the operand stack.
- Otherwise, if *value1* is equal to *value2*, the `int` value 0 is pushed onto the operand stack.
- Otherwise, if *value1* is less than *value2*, the `int` value -1 is pushed onto the operand stack.
- Otherwise, at least one of *value1* or *value2* is NaN. The *dcmpg* instruction pushes the `int` value 1 onto the operand stack and the *dcmpl* instruction pushes the `int` value -1 onto the operand stack.

Floating-point comparison is performed in accordance with IEEE 754. All values other than NaN are ordered, with negative infinity less than all finite values and positive infinity greater than all finite values. Positive zero and negative zero are considered equal.

## Notes

The *dcmpg* and *dcmpl* instructions differ only in their treatment of a comparison involving NaN. NaN is unordered, so any `double` comparison fails if either or both of its operands are NaN. With both *dcmpg* and *dcmpl* available, any `double` comparison may be compiled to push the same *result* onto the operand stack whether the comparison fails on non-NaN values or fails because it encountered a NaN. For more information, see [§3.5](3.5.md).
