[Coco] Performing a modulo operation

William Astle lost at l-w.ca
Wed Feb 13 15:14:03 EST 2013


On 13-02-13 01:07 PM, Alan Bryan wrote:
> Is there a way, preferably in CoCo BASIC or in 6809 assembly language to
> perform a Modulo Operation?
>
> For example: 7 modulo 3 should be 1 (since 3 goes into 7 two times with a
> remainder of 1)

In basic, you can do

M=N-INT(N/D)*D

where M is the modulus, N is the dividend (7 in your example) and D is 
the divisor (3 in your example). That should work for positive numbers. 
I'm not sure it does the right thing on negative numbers - that is left 
as an exercise for the bored.



More information about the Coco mailing list