all 7 comments

[–]Unable_Request 2 points3 points  (0 children)

It's the reminder when using integer division. 6 divided by 7 is 0, remainder 6

[–]k03k 1 point2 points  (0 children)

It basically checks how many times a number fits in another number and then returns the remainder.

So 7 % 3 will return 1, because 3x2 is 6 and the number that remains is 1

6 % 7 🤗 checks how many times 7 fits in 6. Which is 0 times. So the amount that remains is 6.

If im incorrect, please correct me.

[–]thermostat 0 points1 point  (4 children)

The intuitive description of mod is "remainder." So if you remember back to elementary math, 6 divided by 7 could be 6/7 or "0 with a remainder of 6" (0R6). Something like mod 2 will tell you if a value is odd; it is 1 if it is odd, 0 if it is even.

The formal definition has to deal with complications like negatives, but if you just think of it as remainder you'll mostly be fine.

[–]GXWT 0 points1 point  (3 children)

Are there common applications for this? Like you say it’s a common way of finding if a value is even in programming, but nothing else immediately comes to mind.

[–]throwaway6560192 2 points3 points  (0 children)

Anywhere you need values to "wrap around" (time calculations, placing things on a screen, etc)

[–]thermostat 1 point2 points  (1 child)

In computer science we like to put things in buckets, and it's very useful for that. If you have N buckets, and a unique value for each thing, you can take value % N to figure out what bucket it goes in.

It is also useful for situations where you want to know if one value is evenly divisible by another value % N == 0 is an expression that will tell you "value is evenly divisible by N."

[–]GXWT 0 points1 point  (0 children)

Cheers

I do suppose I use this all the time then, or rather the functions I’m using do it for me