title: "Arithmetic" linkTitle: "Arithmetic" category: Script weight: 10
OP_MULPOW2
a b OP_MULPOW2 -> c
Pops the top two stack elements. Multiplies a by 2^b. b may be negative. Overflows result in a script error.
OP_DIV
Opcode (decimal): 150 Opcode (hex): 0x96
Return the integer quotient of a and b. If the result would be a non-integer it is rounded towards zero.
a b OP_DIV -> out
where a and b are interpreted as numeric values
The operator must fail if:
!isnum(a) || !isnum(b). Fail if either operand is not a numeric value.b == 0. Fail ifbis equal to any type of zero.
Impact of successful execution:
- stack memory use reduced
- number of elements on stack is reduced by one
Unit tests:
a b OP_DIV -> failurewhere!isnum(a)or!isnum(b). Both operands must be numeric valuesa 0 OP_DIV -> failure. Division by positive zero (all sizes), negative zero (all sizes),OP_027 7 OP_DIV -> 3,27 -7 OP_DIV -> -3,-27 7 OP_DIV -> -3,-27 -7 OP_DIV -> 3. Check negative operands. Pay attention to sign.- check valid results for operands of different lengths
0..4
OP_MOD
Opcode (decimal): 151 Opcode (hex): 0x97
Returns the remainder after dividing a by b. The output will be represented using the least number of bytes required.
a b OP_MOD -> out
where a and b are interpreted as numeric values
The operator must fail if:
!isnum(a) || !isnum(b). Fail if either operand is not a numeric value.b == 0. Fail ifbis equal to any type of zero.
Impact of successful execution:
- stack memory use reduced (one element removed)
- number of elements on stack is reduced by one
Unit tests:
a b OP_MOD -> failurewhere!isnum(a)or!isnum(b). Both operands must be numeric values.a 0 OP_MOD -> failure. Division by positive zero (all sizes), negative zero (all sizes),OP_027 7 OP_MOD -> 6,27 -7 OP_MOD -> 6,-27 7 OP_MOD -> -6,-27 -7 OP_MOD -> -6. Check negative operands. Pay attention to sign.- check valid results for operands of different lengths
0..4and returning result zero