10.5 Floating- Point Arithmetic

COS2621 - Computer Organisation · 10. Computer Arithmetic

10.5 Floating-Point Arithmetic

Introduction to Floating-Point Arithmetic

Floating-point arithmetic is a method used to represent real numbers in a way that can accommodate a wide range of values. This representation is essential in computer systems for performing calculations that require precision, such as scientific computations. The floating-point representation consists of three main components: the sign, the exponent, and the significand (or mantissa).

Floating-Point Representation

In the IEEE 754 standard, which is the most widely used format for floating-point representation, a number is represented as:

value = (-1)sign × significand × 2(exponent - bias)

Here, the sign bit indicates whether the number is positive or negative, the significand holds the significant digits of the number, and the exponent determines the scale or magnitude of the number. The bias is a constant that allows for both positive and negative exponents.

Example of Floating-Point Representation

Consider the decimal number 45.75. To convert this to IEEE 754 single-precision format:

  1. Convert the number to binary: 45 in binary is 101101 and 0.75 in binary is 0.11. Thus, 45.75 in binary is 101101.11.
  2. Normalize the binary number: Move the binary point to the right of the first 1: 1.011011 × 25.
  3. Determine the sign bit: Since 45.75 is positive, the sign bit is 0.
  4. Calculate the exponent: The bias for single precision (8 bits) is 127. Therefore, exponent = 5 + 127 = 132, which is 10000100 in binary.
  5. Write the significand: Drop the leading 1 from the normalized form and take the next 23 bits: 01101100000000000000000.

Combining these parts gives:

  • Sign bit: 0
  • Exponent: 10000100
  • Significand: 01101100000000000000000

The final IEEE 754 representation of 45.75 in single precision is:

0 10000100 01101100000000000000000

Floating-Point Arithmetic Operations

Floating-point arithmetic includes operations such as addition, subtraction, multiplication, and division. Each operation must consider the exponent and significand separately.

Example: Floating-Point Addition

To add two floating-point numbers, align their exponents. Consider 3.5 (represented as 0 01111111 11000000000000000000000) and 4.25 (represented as 0 10000000 00101000000000000000000).

  1. Align the exponents: 3.5 must be adjusted to match the exponent of 4.25: 3.5 becomes 0 10000000 11100000000000000000000.
  2. Add the significands: 11100000000000000000000 + 00101000000000000000000 = 10001000000000000000000.
  3. Normalize the result if necessary and adjust the exponent accordingly.

Watch out: Ensure that you always align the exponents before performing addition or subtraction.

Summary

  • Floating-point arithmetic allows representation of real numbers.
  • IEEE 754 standard is the most common format.
  • Operations involve adjusting exponents and manipulating significands.

Check your understanding

  • What are the three components of floating-point representation?
  • How do you convert a decimal number to IEEE 754 format?
  • What steps are involved in adding two floating-point numbers?

Test yourself

5 quick questions on this lesson. Pick an answer to see if you're right.

  1. 1. What is the bias value used in the exponent for IEEE 754 single-precision format?

  2. 2. ___ instructions provide computational capabilities for processing numeric data.

  3. 3. In IEEE 754 single-precision format, how many bits are used for the exponent?

  4. 4. Suppose AL contains the value 8Ah What will be the result of the following instruction? sar al, 3

  5. 5. Which one of the following is a representation of an AND gate?