@Modulo (JavaScript)
Returns the remainder of a division operation.
Defined in
@Functions (JavaScript)Syntax
@Modulo(value:double, divider:double)
: double
Parameter | Description |
---|---|
value |
The value to be divided. |
divider |
The value to divide by. Cannot be 0 (results in NaN). |
Return value | Description |
---|---|
double |
The remainder. |
Usage
The parameters and return value can be arrays. The operation acts on the corresponding elements.Examples
(1) This example uses @Modulo to determine if numbers are even or odd.function p(stuff) {
print("<<<" + stuff + ">>>");
}
for(i = 0; i < 10; i++) {
if(@Modulo(i, 2) == 0)
p(i + " is even");
else
p(i + " is odd");
}
(2) This example uses @Modulo to return an integer quotient and the remainder of a division operation.
function p(stuff) {
print("<<<" + stuff + ">>>");
}
function intdiv(n, d) {
var a = new Array();
n = @Round(n);
d = @Round(d);
var m = @Modulo(n, d);
a.push((n - m) / d);
a.push(m);
return(a);
}
var x = intdiv(25, 4);
p("25 / 4 = " + x[0] + " remainder " + x[1]);