Documentation Comments
Use this form to comment on this topic. You can also provide any general observations about the Online Documentation, or request that additional information be added in a future release.
RealityV15.1Online Documentation (MoTW) Revision 7
MOD Function (DataBasic) (m618703+mod_f.htm)
Divides one number by another and returns the modulo.
MOD(expression1,expression2)
REM(expression1,expression2)
expression1, expression2
are any valid DataBasic expressions, or any strings, substrings, or values,
that evaluate to numeric values.
Returns the modulo when expression1 is divided by expression2.
expression2 cannot be zero.
The sign of the result is the same as the sign of expression2.
While MOD (or REM) is typically used with integer operands, it also works for floating point values. For example, MOD(4.3, 2.1) returns 0.1.
MOD returns a value calculated as follows:
MOD(A,B) = A - (ROUND((A/B) - 0.5, 0) * B)
For positive values of expression1 and expression2,
MOD() returns the remainder when expression1 is divided by expression2.
To calculate the remainder for negative numbers, use the formula A - (INT(A/B) * B)
.
Note: This behaviour can be changed with the REM.MOD compatibility option.
Because MOD returns zero when expression1 is exactly divisible by expression2, this function is typically used to test whether a number is a multiple of another number.
IF MOD(A,2) THEN PRINT 'ODD' ELSE
PRINT 'EVEN'
END
Determines if a number is odd or even and prints appropriate message.
INPUT NUM
IF REM(NUM,3) THEN STOP ELSE GO 100
Tests to see if NUM is a multiple of 3. If it isn't, the program terminates; otherwise, control transfers to statement 100.