The difference between the modulo (MoD) and the Take-up (REM)--matlab study notes

Source: Internet
Author: User

For an integer, a, or a method to find the remainder of the operation is divided into the following two steps:

1. Seeking integer quotient: c=a/b

2. Calculating the modulus or remainder: r=a-(c*b)

Modulo operation and redundancy operation are different in the first step.

The remainder operation discards the decimal place in the 0 direction of the quotient value

The modulo operation discards the decimal place in the negative infinity direction of the quotient value for example:

4/(-3) approximately equals-1.3 the quotient value discards the decimal bit to 0 in the time of the remainder operation. 1

The quotient value discards the decimal bit to 2 in the negative infinity direction during the modulo operation

So

4rem ( -3) =1 4mod (-3) =-2


Take the remainder, follow as far as possible to let the business to 0 close to the principle of modulo, follow as far as possible to the negative infinity close to the principle of the symbol, the two will not conflict.

For example, 7/3=2.3,

Produced two quotient of 2 and 3 7=3*2+1 or 7=3*3+ (-2).

So, 7rem3=1,7mod3=1.

Symbols are not the same, they create conflicts.

For example, 7/(-3) =-2.3,

Generated two quotient-2 and-3 7 = (-3) * (-2) +1 or 7 = (-3) * (-3) + (-2).

Therefore, 7rem ( -3) =1,7mod (-3) = (-2)


Usually, the modulo operation is called the remainder operation,

They return the result as a remainder. The only difference between REM (take-up) and mod (modulo) is:

When x and Y are the same sign, two function results are equivalent;

When the symbols for x and y are not the same, the REM function results in the same symbol as x, while mod and y are the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.