BASIC question

in basic, is there a good way to tell if one variable is evenly divisible by another? i vaguely remember there being someing, but i can’t quite get it.

hell, it took me 45 mins of syntax errors and bad file number etc to rediscover pset…

anyway, i was thinking of something like taking the quotient, and doing something like func(quotient)=x, where func is some command which takes the closest whole number, and if quotient = x then all is sweet?

jb

dammit.

it’s int.

int(x).

sorry.

jb

What flavour of BASIC?

Some BASIC’s have both the “/” and “” operators where “” returns the integer quotient. So you can test:

IF a/b = a\b THEN…

Most elegant is the MOD operator:

If A mod B = 0 THEN…

The function you’re looking for is MOD, which returns the remainder of a division rather than the quotient.

If you don’t have the modulo function, use IF A = INT(A/B)*B THEN

The modulus operator is % in many language.

For instance x % y should return the remainder of x / y.

Or if ( (x%y) == 0) then it is evenly divisible. Modulus is an integer operation at the CPU as is very fast. Much faster than any routines that use floating point routines (division).