Thread: Modulus Operator

  1. #1
    Unregistered
    Guest

    Modulus Operator

    The modulus operator seems odd. Does it exist because of integer truncation?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >The modulus operator seems odd.
    How so? After a division of two numbers there is a remainder, the modulus operator gives you that value.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    And that is excelent to know for alot of mathematical stuff. Like finding prime numbers . finding out deviations etc,,,

  4. #4
    Unregistered
    Guest
    What I should have asked is, "If we didn't have truncation, would we still have the modulus operator?"

  5. #5
    Unregistered
    Guest
    If we didn't have truncation, finding the square root of one hundred and twenty would crash a computer.

  6. #6
    Unregistered
    Guest
    Was the modulus operator developed to recover what is lost after integer truncation?

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    Not as far as i know. It is a free standing full fledge operator just as +-*/. I don't see any connection between the truncation and modolus

  8. #8
    Unregistered
    Guest
    Yes it is a freestanding operator.
    -Nic

  9. #9
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    How do u calculate a mod of something in terms of computer? Like how does the comp calculates it? Human can calculate a remainder of a number by doing working outs on a piece of paper i know.

  10. #10
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >Human can calculate a remainder of a number by doing working
    >outs on a piece of paper i know.

    You can translate that algorithm to C.

    9 / 4 = 2
    4 * 2 = 8
    9 - 8 = 1

    so

    9 % 4 = 9 - (9 / 4 * 4) = 1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modulus Operator!
    By siLent0 in forum C Programming
    Replies: 7
    Last Post: 05-16-2008, 08:53 AM
  2. modulus operator with double operands?
    By chickenandfries in forum C Programming
    Replies: 7
    Last Post: 03-28-2008, 07:21 AM
  3. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM