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

# drem

## Operation

Remainder `double`

## Format

```
drem
```

## Forms

*drem* = 115 (0x73)

## Operand Stack

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

..., *result*

## Description

Both *value1* and *value2* must be of type `double`. The values are popped from the operand stack. The `double` *result* is calculated and pushed onto the operand stack.

The result of a *drem* instruction is not the same as the result of the remainder operation defined by IEEE 754, due to the choice of rounding policy in the Java Virtual Machine ([§2.8](2.8.md)). The IEEE 754 remainder operation computes the remainder from a rounding division, not a truncating division, and so its behavior is *not* analogous to that of the usual integer remainder operator. Instead, the Java Virtual Machine defines *drem* to behave in a manner analogous to that of the integer remainder instructions *irem* and *lrem*, with an implied division using the round toward zero rounding policy; this may be compared with the C library function `fmod`.

The result of a *drem* instruction is governed by the following rules, which match IEEE 754 arithmetic except for how the implied division is computed:

- If either *value1* or *value2* is NaN, the result is NaN.
- If neither *value1* nor *value2* is NaN, the sign of the result equals the sign of the dividend.
- If the dividend is an infinity or the divisor is a zero or both, the result is NaN.
- If the dividend is finite and the divisor is an infinity, the result equals the dividend.
- If the dividend is a zero and the divisor is finite, the result equals the dividend.
- In the remaining cases, where neither operand is an infinity, a zero, or NaN, the floating-point remainder *result* from a dividend *value1* and a divisor *value2* is defined by the mathematical relation *result* = *value1* - (*value2* \* *q*), where *q* is an integer that is negative only if *value1* / *value2* is negative, and positive only if *value1* / *value2* is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of *value1* and *value2*.

Despite the fact that division by zero may occur, evaluation of a *drem* instruction never throws a run-time exception. Overflow, underflow, or loss of precision cannot occur.

## Notes

The IEEE 754 remainder operation may be computed by the library routine `Math.IEEEremainder` or `StrictMath.IEEEremainder`.
