Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

267 MOD modulus Purpose The function MOD gives the remainder after division. When doing division with whole numbers (I emphasise – with whole numbers) it is sometimes useful to know the remainder. For example 14 divided by 5 leaves a remainder of 4 (14=2*5+4). Similarly PRINT 14 MOD 5 would print 4 . The whole number part of the above division is given by the function DIV . Thus PRINT 14 DIV 5 would print 2 . Notice that the result of both DIV and MOD is always a whole number. In fact all numbers used in the calculation of the function are first converted to integers (using internal truncation) before the computer calculates the result.

Thus 14 DIV 5 gives 2 14.6 DIV 5.1 gives 2 14 MOD 5 gives 4 14.6 MOD 5.1 gives 4 The second example ( 14.6 DIV 5.1 ) is really the same as the first. However 14.6 DIV 4.9 gives 3 and 14.6 MOD 4.9 gives 2 are quite different. In effect the computer sees them as 14 DIV 4 14 MOD 4 Examples 100 LET X=A MOD B PRINT length MOD 12