is there a mod operator? example c = b%a or c = b mod a e.g., 5%2 = 1
Yes,
if(Time.frameCount%10 == 0)
returns true every 10 frames
If you are looking for a math function though, just use Javascripts %-operator.
Meaning, if you want to calculate number mod 2 use number%2
The value of this operation is the division remainder (9%2 = 1)
You can. Just Do (a = a % b) because (a %= b) does not work...
The % operator is the Remainder operator
Example:
-3 % 3 → 0
-2 % 3 → -2
-1 % 3 → -1
0 % 3 → 0
1 % 3 → 1
2 % 3 → 2
3 % 3 → 0
To do a real Modulo, you need to make or find a function similar to this:
function modulo(dividend : int, divisor : int) : int {
return (((dividend) % divisor) + divisor) % divisor;
}
Results:
-3 % 3 → 0
-2 % 3 → 1
-1 % 3 → 2
0 % 3 → 0
1 % 3 → 1
2 % 3 → 2
3 % 3 → 0
Notice you get the same 0, 1, 2 cycle even when you reach the negative numbers. With this, you can get a consistent indexing for say like enumerators or arrays.
Note:
This assumption is from Google calculator’s -2 % 3 = 1 in contrast with JavaScripts -2 % 3 = -2.