Skip to main content
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Overview

Opcode: 0x05 Introduced: Frontier (EVM genesis) SDIV performs signed integer division on two 256-bit values interpreted as two’s complement signed integers. The result is truncated toward zero (not toward negative infinity like some languages). Like DIV, division by zero returns 0. Additionally, SDIV has special handling for the edge case of dividing the minimum signed integer by -1.

Specification

Stack Input:
Stack Output:
Gas Cost: 5 (GasFastStep) Operation:

Behavior

SDIV interprets 256-bit values as signed integers using two’s complement:
  • Bit 255 (MSB) determines sign: 0 = positive, 1 = negative
  • If b = 0: Returns 0 (no exception)
  • If a = MIN_INT and b = -1: Returns MIN_INT (overflow case)
  • Otherwise: Returns a / b truncated toward zero
Truncation toward zero:
  • Positive quotient: rounds down (e.g., 7/2 = 3)
  • Negative quotient: rounds up (e.g., -7/2 = -3, not -4)

Examples

Basic Signed Division

Negative Dividend

Negative Divisor

Both Negative

Truncation Toward Zero

MIN_INT / -1 Edge Case

Gas Cost

Cost: 5 gas (GasFastStep) SDIV has the same gas cost as DIV despite additional sign handling: Comparison:
  • ADD/SUB: 3 gas
  • MUL/DIV/MOD/SDIV/SMOD/SIGNEXTEND: 5 gas
  • ADDMOD/MULMOD: 8 gas
The sign interpretation adds no gas overhead.

Edge Cases

Division by Zero

MIN_INT Special Cases

Zero Division Results

Common Usage

Signed Arithmetic

Directional Calculations

Fixed-Point Signed Math

Implementation

Testing

Test Coverage

Security

Sign Interpretation

MIN_INT Overflow

Truncation Behavior

Safe Signed Division

Benchmarks

SDIV performance identical to DIV: Execution time:
  • ADD: 1.0x
  • MUL: 1.2x
  • SDIV: 2.5x (same as DIV)
Gas cost:
  • 5 gas per signed division
  • No overhead for sign handling
  • ~200,000 signed divisions per million gas

References