
-----------------------------------
mercuryy
Mon Jun 20, 2005 4:03 pm

mod function
-----------------------------------
I am a bit confused about how to predict the output using the mod function for negative number. 
for example. How do you calculate 

  -2 mod 5
  -5 mod 2
   2 mod -5

etc. in turing without actually running the program?[/b]

-----------------------------------
Delos
Mon Jun 20, 2005 6:20 pm


-----------------------------------
It is no different from looking at a positive number.  Since 'mod' returns the remainder of a division, say you test 5 mod 2.  You'll get 1.  -5 mod 2?  You'll still get 1.  Don't think about it too hard - but suffice it to say that "remainder of negative one" and "remainder of positive one" still both mean that there 1 remaining.

-----------------------------------
mercuryy
Mon Jun 20, 2005 6:36 pm


-----------------------------------
what about -2 mod 5 and 2 mod 5. -2 mod 5 is obviously 2, so why does -2 mod 5 equals to 3?

-----------------------------------
MysticVegeta
Mon Jun 20, 2005 6:49 pm


-----------------------------------
Let me simplify it down for you, mod really is ->
var num : int := 5
var num2 : int := -2
put num - ((num div num2)*num2)

