# Errors in Computer Arithmetic

- Pages:
**3** - Word count:
**695** - Category: Computers

A limited time offer! Get a custom sample essay written according to your requirements urgent 3h delivery guaranteed

Order NowComputer Arithmetic:

1. Integer arithmetic:

Virtually all the computer offer integer arithmetic. The two properties of integer arithmetic are as follows a) Result of any arithmetic operation is an integer

b) Result is always exact with two exceptions

• Range of integer that can be represented is not infinite but is bounded above and below. • The result of the division operation is given as the combination of the quotient and the remainder. Remainder of the result is always truncated. 2. Floating point arithmetic

Due to economic consideration, computers are designed such that each location in memory at stores only a finite number of digits. For example, A computer has a memory in which each location can store one or more signs. There are two methods for representing the real numbers.

Assume a fix position for decimal point and store all number (after appropriate shifting if necessary) with assumed decimal point. If such convention is used, maximum and minimum numbers that can be stored are 9999.99 and 0.00001 respectively

Another convention aims to preserve the maximum no of significant digits. This representation is called normalized floating point mode of representation and storing real number. In this, real number is expressed as combination of mantissa and exponent. The mantissa is made lass than one greater that or equal to 0.1 exponent is power of 10 which multiplies mantissa. Memory location with 6 digit are divided in two parts, 4 digits for mantissa and 2 digits for exponent. While storing number the leading digit is mantissa is always made nonzero by appropriate shifting and adjusting the value of exponent.

Shifting the mantissa to left till its most significant digit is nonzero is called normalization. Normalization is useful to preserve the maximum number of useful digits. Maximum range for the number to represent in the computer with the help of the above method is 0.10000E-99 to 9999.99E99.

Arithmetic operation with normalization floating point numbers

Addition

Let two number to be added are x and y and the result of the addition operation is to be stored in z. Let fraction part and exponent part of these numbers are ƒx, ƒy, and ƒz and Ex, Ey, Ez respectively.

Algorithm for addition (assume that ƒx>ƒy)

Step 1.

Ez = Larger of Ex and Ey.

Step 2.

Shift ƒy to right by Ex-Ey.

Step 3.

Add ƒz = ƒx + ƒy

Step 4.

Normalize.

If the absolute value of ƒz is greater than 1 shift decimal point of ƒy to left of most significant digit and increase Ez by 1. This give z = ƒz 10Ez

Subtraction

Subtraction is nothing but addition of the number and the complement of other number. However the subtraction of mantissa may result in a number less than 0.1. In such cases decimal point should be shifted to the left of most significant digit and the exponent of the result should than be decreased accordingly.

Multiplication

Let two number to be multiplied are x and y and the result of the multiplication operation is to be stored in z. Let fraction part and exponent part of these numbers are ƒx, ƒy, and ƒz and Ex, Ey, Ez respectively.

Algorithm for multiplication of two numbers.

Step 1.

Multiply the fraction part ƒz = ƒx ∙ ƒy

Step 2.

Add the exponent Ez = Ex + Ey

Step 3.

Z = ƒz * 10Ez

Step 4.

Normalize.

Division

Let two number to be multiplied are x and y and the result of the multiplication operation is to be stored in z. Let fraction part and exponent part of these numbers are ƒx, ƒy, and ƒz and Ex, Ey, Ez respectively.

Algorithm for multiplication of two numbers.

Step 1.

Divide the fraction part ƒz = ƒx ÷ ƒy

Step 2.

Subtract the exponent Ez = Ex – Ey

Step 3.

Z = ƒz * 10Ez

Step 4.

Normalize.

Consequence of normalized floating point representation of the number.

1. Number had to truncated to fit into four mantissa digit allowed in our early computers. These truncation leads to a number of surprising results. However Arithmetic is performed with floating point numbers. 2. Associative law and distributive law of arithmetic are not always valid.