Skip to content

Latest commit

 

History

History
51 lines (30 loc) · 1.61 KB

iii.3.31-div.md

File metadata and controls

51 lines (30 loc) · 1.61 KB

III.3.31 div – divide values

Format Assembly Format Description
5B div Divide two values to return a quotient or floating-point result.

Stack Transition:

…, value1, value2 → …, result

Description

result = value1 div value2 satisfies the following conditions:

  • |result| = |value1| / |value2|, and

  • sign(result) = +, if sign(value1) = sign(value2), or
    –, if sign(value1) ~= sign(value2)

The div instruction computes result and pushes it on the stack. Integer division truncates towards zero.

Floating-point division is per IEC 60559:1989. In particular, division of a finite number by 0 produces the correctly signed infinite value and

  • 0 / 0 = NaN

  • infinity / infinity = NaN

  • X / infinity = 0

The acceptable operand types and their corresponding result data type are encapsulated in Table 2: Binary Numeric Operations.

Exceptions:

Integral operations throw System.ArithmeticException if the result cannot be represented in the result type. (This can happen if value1 is the smallest representable integer value, and value2 is -1.)

Integral operations throw DivideByZeroException if value2 is zero.

Floating-point operations never throw an exception (they produce NaNs or infinities instead, see Partition I).

Example:

 
+14 div +3 is 4
+14 div -3 is -4
-14 div +3 is -4
-14 div -3 is 4

Correctness and Verifiability

See Table 2: Binary Numeric Operations.