The difference between __c and modulo in C language

Source: Internet
Author: User
Tags modulus
The difference between the remainder in C and the modulus of taking

Have not noticed this problem before, check a bit today, feel too cumbersome, now simple and clear summary

For integer number A,b, the method of modulo operation or remainder operation is:

1. Find the integer quotient: c = A/b;

2. Computational model or remainder: R = a-c*b.

The modulus operation and the remainder operation are different in the first step: the remainder operation is rounded in the 0 direction when the value of C is taken, while the modulo operation rounds in the negative infinity direction when calculating the value of C.

The so-called round to the 0 direction, that is, the decimal point as the boundary, the decimal part directly removed. such as (INT) -1.324=-1 (also called truncation method);

Rounding in the negative infinity direction means that the end result is smaller than the real value. such as (int) -1.324=-2; (int here is cast data type)

Note that C refers to the business;

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.