View previous topic :: View next topic |
Author |
Message |
Ax3l Cheater Reputation: 1
Joined: 22 May 2011 Posts: 37
|
Posted: Sun Jun 19, 2011 7:31 am Post subject: Modulus operator |
|
|
Hey , I really want to know what the modulus operator is, because I tried to understand this months before , and after hours I still dont' know
I googled and it says the modulus operator returns the remainder of division of a number by another one.
but I don't get it , I tried alot in C++
Code: | int a=2,b=3,c;
c= a%b;
|
it returns 2
but how ? 2 /3 = 0.6666 or 1
when I assigned 100 to a it returned 1
again I don't understand , 100/3 = 33
EDIT : Never mind I GET IT
100/3 = 33
33*3 =99
100-99 =1
something like that
|
|
Back to top |
|
|
Innovation Grandmaster Cheater Reputation: 12
Joined: 14 Aug 2008 Posts: 617
|
Posted: Sun Jun 19, 2011 8:52 am Post subject: |
|
|
When two is divided by three, three cannot go into two even once. Therefore, the remainder is two.
|
|
Back to top |
|
|
AhMunRa Grandmaster Cheater Supreme Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Mon Jun 20, 2011 11:36 am Post subject: |
|
|
@OP it rounds up, 100 / 3 is 33.3333333333333333 the .33333333333333 rounded to 1 is the modulous of 100 / 3.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Mon Jun 20, 2011 12:37 pm Post subject: |
|
|
100 % 6 = 4
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Ax3l Cheater Reputation: 1
Joined: 22 May 2011 Posts: 37
|
Posted: Mon Jun 20, 2011 1:33 pm Post subject: |
|
|
AhMunRa wrote: | @OP it rounds up, 100 / 3 is 33.3333333333333333 the .33333333333333 rounded to 1 is the modulous of 100 / 3. |
Doesn't it round down ?
100/3 = 33.3333333
34*3 = 102
_________________
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Mon Jun 20, 2011 1:55 pm Post subject: |
|
|
you had it correct in the first posts. Modulus is what is left after being divided by the given value
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
lucidity Advanced Cheater Reputation: 0
Joined: 16 Feb 2011 Posts: 91
|
Posted: Mon Jun 20, 2011 1:56 pm Post subject: |
|
|
Modulus is not simply rounding the decimal portion of the quotient up, consider:
200 / 3 = 66.66666666666
Remainder is 0.6666666666, rounded up is 1
200 - 1 = 199
199 / 3 = 66.33333333333, which is incorrect
Modulus is truncated rounding of the quotient and returning the remainder:
200 / 3 = 66.66666666666
Truncating the quotient, you get 66.
200 - (3 * 66) = 2
200 - 2 = 198
198 / 3 = 66, which is correct
_________________
» Antec Twelve Hundred Full Tower » EVGA E760 CLASSIFIED » EVGA GeForce GTX 580 SuperClocked 1536MB » i7-980XE » CORSAIR DOMINATOR 6GB PC3 12800 DDR3 » OS: Intel X25-M SSD » Game Storage: Raid-0 2 x WD VelociRaptor 10000 RPM » CE Cache Drive: 500GB WD Caviar » Power Supply: OCZ Z Series Gold 1000W |
|
Back to top |
|
|
|