HTBasic Help
×
Menu
Index

MOD

Returns remainder after integer division.
 
 dividend MOD divisor
 
Usage:
I=D MOD 16
PRINT "Inches"=";Length MOD 12
 
Example:           MOD.BAS
 
Description:
X MOD Y is the remainder from a division which produces an integral quotient and is defined as X - Y * (X DIV Y). If one or both of the operands are REAL, the result is REAL; otherwise the result is INTEGER.
 
Note that MOD is similar to MODULO but gives a different result only when X/Y is negative. This is because MODULO uses the formula X - Y * INT(X/Y), whereas MOD uses X - Y * (X DIV Y). This means when X/Y is negative INT(X/Y) converts to integer by truncation toward negative infinity, whereas with MOD,  (X DIV Y) converts to integer by truncation toward zero.
 
 
See Also: