section_path: Types/Integer arithmetic
section_name: Integer arithmetic
paragraph_text: Integer arithmetic
  
  Integer arithmetic is the branch of arithmetic that deals with the manipulation of positive and negative whole numbers. Simple one-digit operations can be performed by following or memorizing a table that presents the results of all possible combinations, like an addition table or a multiplication table. Other common methods are verbal counting and finger-counting.
  
  For operations on numbers with more than one digit, different techniques can be employed to calculate the result by using several one-digit operations in a row. For example, in the method addition with carries, the two numbers are written one above the other. Starting from the rightmost digit, each pair of digits is added together. The rightmost digit of the sum is written below them. If the sum is a two-digit number then the leftmost digit, called the "carry", is added to the next pair of digits to the left. This process is repeated until all digits have been added. Other methods used for integer additions are the number line method, the partial sum method, and the compensation method. A similar technique is utilized for subtraction: it also starts with the rightmost digit and uses a "borrow" or a negative carry for the column on the left if the result of the one-digit subtraction is negative.
  
  A basic technique of integer multiplication employs repeated addition. For example, the product of 3 × 4 {\displaystyle 3\times 4} can be calculated as 3 + 3 + 3 + 3 {\displaystyle 3+3+3+3}. A common technique for multiplication with larger numbers is called long multiplication. This method starts by writing the multiplier above the multiplicand. The calculation begins by multiplying the multiplier only with the rightmost digit of the multiplicand and writing the result below, starting in the rightmost column. The same is done for each digit of the multiplicand and the result in each case is shifted one position to the left. As a final step, all the individual products are added to arrive at the total product of the two multi-digit numbers. Other techniques used for multiplication are the grid method and the lattice method. Computer science is interested in multiplication algorithms with a low computational complexity to be able to efficiently multiply very large integers, such as the Karatsuba algorithm, the Schönhage-Strassen algorithm, and the Toom-Cook algorithm. A common technique used for division is called long division. Other methods include short division and chunking.
  
  Integer arithmetic is not closed under division. This means that when dividing one integer by another integer, the result is not always an integer. For instance, 7 divided by 2 is not a whole number but 3.5. One way to ensure that the result is an integer is to round the result to a whole number. However, this method leads to inaccuracies as the original value is altered. Another method is to perform the division only partially and retain the remainder. For example, 7 divided by 2 is 3 with a remainder of 1. These difficulties are avoided by rational number arithmetic, which allows for the exact representation of fractions.
  
  A simple method to calculate exponentiation is by repeated multiplication. For instance, the exponentiation of 3 4 {\displaystyle 3^{4}} can be calculated as 3 × 3 × 3 × 3 {\displaystyle 3\times 3\times 3\times 3}. A more efficient technique used for large exponents is exponentiation by squaring. It breaks down the calculation into a number of squaring operations. For example, the exponentiation 3 65 {\displaystyle 3^{65}} can be written as (((((3 2) 2) 2) 2) 2) 2 × 3 {\displaystyle (((((3^{2})^{2})^{2})^{2})^{2})^{2}\times 3}. By taking advantage of repeated squaring operations, only 7 individual operations are needed rather than the 64 operations required for regular repeated multiplication. Methods to calculate logarithms include the Taylor series and continued fractions. Integer arithmetic is not closed under logarithm and under exponentiation with negative exponents, meaning that the result of these operations is not always an integer.