Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do mod without a mod operator?

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.

like image 799
tladuke Avatar asked May 03 '10 23:05

tladuke


3 Answers

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.

like image 120
John Källén Avatar answered Oct 10 '22 19:10

John Källén


a mod n = a - (n * Fix(a/n))

like image 6
Strelok Avatar answered Oct 10 '22 18:10

Strelok


For posterity, BrightScript now has a modulo operator, it looks like this:

c = a mod b
like image 6
Nas Banov Avatar answered Oct 10 '22 20:10

Nas Banov