Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 mod function
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mercuryy




PostPosted: Mon Jun 20, 2005 4:03 pm   Post subject: 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]
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon Jun 20, 2005 6:20 pm   Post subject: (No subject)

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




PostPosted: Mon Jun 20, 2005 6:36 pm   Post subject: (No subject)

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




PostPosted: Mon Jun 20, 2005 6:49 pm   Post subject: (No subject)

Let me simplify it down for you, mod really is ->
code:
var num : int := 5
var num2 : int := -2
put num - ((num div num2)*num2)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: