Swift to find the remainder operation

Source: Internet
Author: User

1 To find the remainder operation2 3To find the remainder operation (a%b) is the number of times B is just good enough to accommodate a, returning the extra portion (remainder). 4Note: The remainder operation (%) is also called modulo operation in other languages. Strictly speaking, however, we look at the result of the operator's operation on negative numbers,"Seeking Redundancy"Than"Take the mold"more appropriate. 5Let's talk about how the remainder is going to be calculated 94, you first calculate how many times 4 will fit into the 9:6art/Remainderinteger_2x.png7 twice times, very good, that remainder is 1 (marked in orange)8 9 in Swift, this is the expression:Ten 9%4    //equals 1 OneIn order to get the result of a% B,%The following equation is computed and the remainder is output as a result: AA = (bx multiples) +remainder - when the multiplier takes the maximum value, it will just fit into a.  -  the put 9 and 4 into the equation, we have 1: - 9= (4X2) +1 -The same method that I came to calculate--9%4: --9%4   //equals-1 +Put 9 and 4 into the equation,-2 is the largest integer taken: --9= (4X-2) + -1 +The remainder is-1.  A  atWhen a negative number B is remainder, the b symbol is ignored. This means that the results of a% B and a%-B are the same.

Swift to find the remainder operation

Related Article

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.