Computer Science Canada Mod vs Rem |
Author: | mirhagk [ Mon Feb 22, 2010 11:21 pm ] |
Post subject: | Mod vs Rem |
Hey guys... this might sound dumb, but is there a difference betweent the rem operator and the mod operator?? |
Author: | TheGuardian001 [ Mon Feb 22, 2010 11:33 pm ] | ||
Post subject: | Re: Mod vs Rem | ||
They appear to work differently with combinations of negative and positive numbers, although I'm not sure why or how they differ, IE:
|
Author: | mirhagk [ Mon Feb 22, 2010 11:38 pm ] |
Post subject: | RE:Mod vs Rem |
alright lol, i was just kinda confused, i was building a prime number generator for an encryption program and i used mod, then i was looking at a previous one i made and it used rem... They don't seem to make a difference performance-wise and the output is the same, I was just curious lol, if anyone knows why let me know k |
Author: | Euphoracle [ Tue Feb 23, 2010 12:20 am ] |
Post subject: | RE:Mod vs Rem |
The rem operator is actually the remainder of the division operation. The mod operator is the modulus operator. Consider -12 mod 5. Basically, it computes a number b, such that 0 <= b <= 5 such that -12 = 5a+b where a is some integer. |
Author: | Turing_Gamer [ Tue Feb 23, 2010 8:32 am ] | ||||
Post subject: | Re: Mod vs Rem | ||||
A mod (modulous?) function counts the number of times a number goes in a loop. For example...
The first number is the main value. The second number is the limit of the loop. ex: If it is 2, then the loop will only go like this: 0, 1, 0, 1... The mod calculates how many times the first number goes into the second number A rem (remainder) function shows after a division how many left overs you have. For example...
The first number is the main value. The second number is the divisor for the problem. The rem acts much like a division sign but it will not give the divided number but the amount you have left. Hope this helps ![]() |
Author: | Euphoracle [ Tue Feb 23, 2010 9:01 am ] |
Post subject: | RE:Mod vs Rem |
^ what http://www.google.ca/search?sourceid=chrome&ie=UTF-8&q=11+mod+2 http://www.google.ca/search?sourceid=chrome&ie=UTF-8&q=99+mod+3 |
Author: | Turing_Gamer [ Tue Feb 23, 2010 12:51 pm ] | ||
Post subject: | Re: Mod vs Rem | ||
Quote: TURING DOCUMENTATION:
The mod (modulo) operator produces the modulo of one number with another. In other words, the result is always a number between 0 and the second operand. If both operands are positive, the result is identical to the remainder operator. For example, 7 mod 2 produces 1 and 12 mod 5 produces 3. Oops, k now I understand. Here is an example...
It goes through a modified remainder process. Program says: My number is 14 and i have to find the mod 5 of it... Let's start! 1(1), 2(2), 3(3), 4(4), 5(5), 6... oops, the number is over the second number (which is 5) so lets start all over again! 6(1), 7(2), 8(3), 9(4), 10(5), 11... Start all over again. 11(1), 12(2), 13(3), 14(4)... Ok, I reached my number what is my bracket number? 4. Alright in that case 14 mod 5 = 4... You get it? |
Author: | DemonWasp [ Tue Feb 23, 2010 4:51 pm ] |
Post subject: | RE:Mod vs Rem |
Don't forget that 5 mod 5 = 0 (in fact, this is true if you replace 5 by any number). |