Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6155137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:22:56+00:00 2026-05-23T20:22:56+00:00

I was previously under the (naive) assumption that the modulus operator returned the remainder

  • 0

I was previously under the (naive) assumption that the modulus operator returned the remainder of division. I was apparently wrong, as -2 % 5 returns 3. I would have thought that 5 divides -2 zero times with -2 as the remainder.

Now I understand the mechanics of how this operation is performed, but my question is why? Could someone give me a link to something that explains why modulus and remainder are not synonymous, or an example of a situation where it would be useful?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:22:58+00:00Added an answer on May 23, 2026 at 8:22 pm

    The result is entirely correct. Modular arithmetic defines the following (I’ll use “congruent” since I can’t type the equal sign with three lines)

    a congruent b mod c iff a-b is a multiple of c, i.e. x * c = (a-b) for some integer x.

    E.g.

    0 congruent 0 mod 5 (0 * 5 = 0-0)
    1 congruent 1 mod 5 (0 * 5 = 1-1)
    2 congruent 2 mod 5 (0 * 5 = 2-2)
    3 congruent 3 mod 5 (0 * 5 = 3-3)
    4 congruent 4 mod 5 (0 * 5 = 4-4)
    5 congruent 0 mod 5 (1 * 5 = 5-0)
    6 congruent 1 mod 5 (1 * 5 = 6-1)
    ...
    

    The same can be extended to negative integers:

    -1 congruent 4 mod 5 (-1 * 5 = -1-4)
    -2 congruent 3 mod 5 (-1 * 5 = -2-3)
    -3 congruent 2 mod 5 (-1 * 5 = -3-2)
    -4 congruent 1 mod 5 (-1 * 5 = -4-1)
    -5 congruent 5 mod 5 (-1 * 5 = -5-0)
    -6 congruent 4 mod 5 (-2 * 5 = -6-4)
    -7 congruent 3 mod 5 (-2 * 5 = -7-3)
    ...
    

    As you can see, a lot of integers are congruent 3 mod 5:
    …, -12, -7, -2, 3, 8, 13, …

    In mathematics, the set of these numbers is called the equivalence class induced by the equivalence relation “congruence”. Our understanding of the remainder and the definition of the “mod” function are based on this equivalence class. The “remainder” or the result of a mod computation is a representative element of the equivalence class. By declaration we have chosen the smallest non-negative element (so -2 is not a valid candidate).

    So when you read -2 mod 5 = x this translates to “Find the smallest non-negative x so that there exists an integer y with y * 5 = -2 – x”, in concordance with the definition of congruence. The solution is y=1 and x = 3 as you can see by simply trying out other values for y.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Access 2007 application (previously in Access 2003) that is running into
Assume that you have a directory under subversion control, that contains some files and
I have a C# project that I previously had targeting .NET 4.0, and now
I have an HTML form that previously was only used for text attributes for
I'm trying to compile with g++ some code previously developed under Visual C++ 2008
From previous experience I had been under the impression that it's perfectly legal (though
Previously I have asked to strip text from a field and convert it to
Previously, I had a class that wrapped an internal System.Collections.Generic.List<Item> (where Item is a
Previously I've asked about inserting a column into a dataset . I now have
I know this has been asked previously however I would like to disable the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.