Computer Science Canada

4 mod 6 = 4? 4 mod 8 = 4?

Author:  person [ Mon Jan 31, 2005 2:30 pm ]
Post subject:  4 mod 6 = 4? 4 mod 8 = 4?

4 mod 6 = 4? 4 mod 8 = 4?
y does this happen?
i though mod returned a remainder

Author:  md [ Mon Jan 31, 2005 3:09 pm ]
Post subject: 

er... perhaps because you are trying to get the remainder when 4 is divided by 6... which just so happens to be 4 as 4 is not divisible by 6... The same is true for 4 mod 8. If you are trying to get the remainder when 8 is divided by four then you should be using 8 mod 4.

If you still don't understand what's going on (and this isn't much of a description i must admit...) then I would recoment the ever helpful google.

Author:  basketball4ever [ Mon Jan 31, 2005 3:12 pm ]
Post subject: 

do you understand mod???

mod finds you the remainder...

since 4 isn't dividisble by 6 or 8... the remainder is going to be 4... its simple math. Confused

Author:  person [ Mon Jan 31, 2005 3:14 pm ]
Post subject: 

Quote:
er... perhaps because you are trying to get the remainder when 4 is divided by 6... which just so happens to be 4 as 4 is not divisible by 6... The same is true for 4 mod 8. If you are trying to get the remainder when 8 is divided by four then you should be using 8 mod 4.


thanx, i get it now

Author:  typon [ Mon Jan 31, 2005 3:22 pm ]
Post subject: 

yea got it ~!~!~!
4 mod [anything greater than 4] = 4

its the other way around if you want to find the remainder. xD

Author:  Viper [ Sat Feb 05, 2005 1:26 pm ]
Post subject: 

if your jus trying to divide its probably easier to us div (not recommended for int)

Author:  Bacchus [ Sat Feb 05, 2005 3:11 pm ]
Post subject: 

div works with int and it probably the best to use cause it rounds it to closes integer, / on the other hand doesnt

Author:  Cervantes [ Sun Feb 06, 2005 9:00 am ]
Post subject: 

Bacchus wrote:
div works with int and it probably the best to use cause it rounds it to closes integer, / on the other hand doesnt

Careful:
Turing Help Reference wrote:

The div operator divides one number by another and produces the integer result, truncated in the direction of zero. For example, 7 div 2 produces 3 and -7 div 2 produces -3.


Turing:

put 5 / 3
put 5 div 3

Author:  Bacchus [ Sun Feb 06, 2005 9:28 am ]
Post subject: 

ok so it rounds down Razz

Author:  bugzpodder [ Sun Feb 06, 2005 11:02 am ]
Post subject: 

whats

Quote:

5 mod -2
-5 mod -2


: