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

# lrem

## Operation

Remainder `long`

## Format

```
lrem
```

## Forms

*lrem* = 113 (0x71)

## Operand Stack

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

..., *result*

## Description

Both *value1* and *value2* must be of type `long`. The values are popped from the operand stack. The `long` *result* is *value1* - (*value1* / *value2*) \* *value2*. The *result* is pushed onto the operand stack.

The result of the *lrem* instruction is such that `(a/b)*b + (a%b)` is equal to `a`. This identity holds even in the special case in which the dividend is the negative `long` of largest possible magnitude for its type and the divisor is -1 (the remainder is 0). It follows from this rule that the result of the remainder operation can be negative only if the dividend is negative and can be positive only if the dividend is positive; moreover, the magnitude of the result is always less than the magnitude of the divisor.

## Run-time Exception

If the value of the divisor for a `long` remainder operator is 0, *lrem* throws an `ArithmeticException`.
