[Coco] What? No MOD?!

Robert Gault robert.gault at att.net
Sun Dec 29 22:52:43 EST 2013


Mark J. Blair wrote:
> I'm fiddling with the idea of writing a simulator for the M-209 cipher machine (a WW2 era mechanical cipher machine used by US forces; bleed-over from another one of my hobbies) in Basic and porting it to various vintage machines that I have. I was surprised to discover that Basic in the CoCo does not include a modulo arithmetic operator. I'm outraged, I tell you! :)
>
> I might write a Model 100 series version first. The Model 100 Basic has a MOD operator for doing modulo arithmetic.
>

Well, unless you are wedded to ROM Basic, you could write your program in 
Basic09 as it does have a MOD function. "MOD Returns the modulus (remainder) of 
a division operation."

As others have suggested it should be relatively simple to create your own Basic 
function with DEF FN or write an assembly version called from Basic with DEFUSR.

A simple formula is MOD(A,B)= B*(A/B-INT(A/B))



More information about the Coco mailing list