How can I do mod without a mod operator?

tladuke picture tladuke · May 4, 2010 · Viewed 12.1k times · Source

This scripting language doesn't have a % or Mod(). I do have a Fix() that chops off the decimal part of a number. I only need positive results, so don't get too robust.

Answer

John Källén picture John Källén · May 4, 2010

Will

// mod = a % b

c = Fix(a / b)
mod = a - b * c

do? I'm assuming you can at least divide here. All bets are off on negative numbers.