Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Mod operator: How does it work?
- Derpyguyytscratch
-
2 posts
Mod operator: How does it work?
I think I'm getting used to scratch operators at this point… But I'm having trouble figuring out one operator in particular.
It's the modulus operator.
Say if I were to do something like this:
It's the modulus operator.
Say if I were to do something like this:
((1) mod (10))What would happen? I honestly have no idea how this thing works
- Voxalice
-
1000+ posts
Mod operator: How does it work?
From () Mod ():
The example you provided in your post (1 mod 10) would just return 1. The () Mod () block (“mod” is short for “modulo”) is an Operators block and a reporter block. It reports the remainder when the first input is divided by the second. For example, when 10 is put in the first input and 3 in the second, the block will report 1; 10 divided by 3 gives a remainder of 1.
- Derpyguyytscratch
-
2 posts
Mod operator: How does it work?
Oh thanks, i thought it was like a range tool or something lol
- PaSc_Clan
-
64 posts
Mod operator: How does it work?
The mod operator finds the remainder after dividing one number by another. It tells you what is left over when the division isn’t exact. I think I'm getting used to scratch operators at this point… But I'm having trouble figuring out one operator in particular.
It's the modulus operator.
Say if I were to do something like this:((1) mod (10))What would happen? I honestly have no idea how this thing works
10 mod 3 = 1
The mod operator is the same as doing this:
([abs v] of ((a) - ((b) * ([floor v] of ((a) / (b))))))
Last edited by PaSc_Clan (Feb. 19, 2025 18:21:18)
- Discussion Forums
- » Help with Scripts
-
» Mod operator: How does it work?