Floating-Point Representation
Notes computer notesFloating-Point Representation
Floating-point representation is a method used in computing to represent real numbers in a way that can accommodate a wide range of values, from very small to very large, with a finite number of digits. This representation is crucial for scientific computations, engineering applications, and any domain where precision and range are important.
Key Components of Floating-Point Representation
- Sign Bit (S):
- The sign bit determines whether the number is positive or negative.
- Typically,
0represents a positive number, and1represents a negative number.
- Exponent (E):
- The exponent is a biased integer that represents the power to which the base (usually 2) is raised.
- The bias is used to allow the representation of both positive and negative exponents.
- For example, in the IEEE 754 standard for 32-bit floating-point numbers, the exponent is 8 bits long with a bias of 127.
- Mantissa (M) or Significand:
- The mantissa represents the significant digits of the number.
- It is a fractional part that, when combined with the exponent, gives the precise value of the number.
- In normalized form, the mantissa is typically represented with an implicit leading
1(i.e.,1.xxxx...), which is not stored explicitly.
IEEE 754 Standard
The IEEE 754 standard is the most widely used standard for floating-point representation. It defines several formats, including:
- Single-Precision (32-bit):
- 1 bit for the sign.
- 8 bits for the exponent.
- 23 bits for the mantissa.
- The bias for the exponent is
127.
- Double-Precision (64-bit):
- 1 bit for the sign.
- 11 bits for the exponent.
- 52 bits for the mantissa.
- The bias for the exponent is
1023.
Representation of a Floating-Point Number
A floating-point number NN can be represented as:
N=(−1)S×M×2(E−bias)
Where:
- S is the sign bit.
- M is the mantissa (including the implicit leading
1in normalized form). - E is the exponent.
- The bias is a constant that depends on the precision (e.g., 127 for single-precision).
Special Values
The IEEE 754 standard also defines special values:
- Zero:
- Represented by an exponent and mantissa of all zeros.
- Can be positive or negative depending on the sign bit.
- Infinity:
- Represented by an exponent of all ones and a mantissa of all zeros.
- Can be positive or negative depending on the sign bit.
- NaN (Not a Number):
- Represented by an exponent of all ones and a non-zero mantissa.
- Used to represent undefined or unrepresentable results, such as the result of dividing zero by zero.