Skip to content

Latest commit

 

History

History
58 lines (35 loc) · 2.41 KB

iii.3.55-rem.md

File metadata and controls

58 lines (35 loc) · 2.41 KB

III.3.55 rem – compute remainder

| Format | Assembly Format | Description | 5D | rem | Remainder when dividing one value by another.

Stack Transition:

…, value1, value2 → …, result

Description:

The rem instruction divides value1 by value2 and pushes the remainder result on the stack.

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

For integer operands

result = value1 rem value2 satisfies the following conditions:

  • result = value1 - value2 × (value1 div value2), and

  • 0 ≤ |result| < |value2|, and

  • sign(result) = sign(value1),

where div is the division instruction, which truncates towards zero.

For floating-point operands

rem is defined similarly as for integer operands, except that, if value2 is zero or value1 is infinity, result is NaN. If value2 is infinity, result is value1. This definition is different from the one for floating-point remainder in the IEC 60559:1989 Standard. That Standard specifies that value1 div value2 is the nearest integer instead of truncating towards zero. System.Math.IEEERemainder (see Partition IV) provides the IEC 60559:1989 behavior.

Exceptions:

Integral operations throw System.DivideByZeroException if value2 is zero.

Integral operations can throw System.ArithmeticException if value1 is the smallest representable integer value and value2 is -1.

Example:

   
+10 rem +6 is 4 (+10 div +6 = 1)
+10 rem -6 is 4 (+10 div -6 = -1)
-10 rem +6 is -4 (-10 div +6 = -1)
-10 rem -6 is -4 (-10 div -6 = 1)

For the various floating-point values of 10.0 and 6.0, rem gives the same values; System.Math.IEEERemainder, however, gives the following values.

   
System.Math.IEEERemainder(+10.0, +6.0) is -2 (+10.0 div +6.0 = 1.666…7)
System.Math.IEEERemainder(+10.0, -6.0) is -2 (+10.0 div -6.0 = -1.666…7)
System.Math.IEEERemainder(-10.0, +6.0) is 2 (-10.0 div +6.0 = -1.666…7)
System.Math.IEEERemainder(-10.0, -6.0) is 2 (-10.0 div -6.0 = 1.666…7)

Correctness and Verifiability:

See Table 2: Binary Numeric Operations.