Results 1 to 4 of 4

Thread: how does mod work with negative numbers?
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Feb 2013
    Posts
    382
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default how does mod work with negative numbers?

    eg mod(4,-13) gives -9 ....how does that work?
    Last edited by daveyc18; Jul 15th, 2019 at 01:54 PM.

  2. #2
    Board Regular
    Join Date
    Jan 2018
    Posts
    267
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    1 Thread(s)

    Default Re: how does mod work with negative numbers?

    Quote Originally Posted by daveyc18 View Post
    eg mod(4,-13) gives -9 ....how does that work?
    You have written 4 mod -13. When integer 4 is divided by integer -13, 4 is divided once with a remainder of -9.

  3. #3
    Board Regular kweaver's Avatar
    Join Date
    May 2018
    Location
    La Jolla, CA
    Posts
    645
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: how does mod work with negative numbers?

    Excel's MOD function is defined as: MOD(n, d) = n - d*INT(n/d)

    When d is negative, the sign of the answer is the same as the sign of the divisor.

    In mod(4,-13): 4-(-13)*INT(4/-13) which is 4-(-13)*(-1) which is 4-13 which is -9.

  4. #4
    MrExcel MVP shg's Avatar
    Join Date
    May 2008
    Location
    The Great State of Texas
    Posts
    21,639
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    14 Thread(s)

    Default Re: how does mod work with negative numbers?

    As it says in Help,

    =MOD(n,d) returns =n-d*INT(n/d)

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •