Resources | Subject Notes | Computer Science
This section details the process of normalising floating-point numbers, a crucial step in representing real numbers within the limited range of a floating-point format. Normalisation ensures that the leading digit (significand) has a leading 1, maximizing precision.
Floating-point numbers are typically represented in a format like IEEE 754. This format has a fixed number of bits allocated to the sign, exponent, and significand (also known as the mantissa). Normalisation is the process of adjusting the binary representation of a number so that it falls within a specific range. Without normalisation, the leading bit of the significand might be zero, leading to a loss of precision and potentially requiring extra bits to represent the same number.
The normalisation process involves two main steps:
Consider the decimal number 12.5. To represent this in binary, we first convert it to binary: 1100.1. This can be written as $1.1001_2 \times 2^3$. The significand is 1.1001, and the exponent is 3. To normalise, we shift the binary point left by 3 positions, resulting in 110010.0. This is equivalent to $1.1001_2 \times 2^3$.
The IEEE 754 standard defines how floating-point numbers are represented. The normalisation process is a fundamental part of this standard. The standard specifies that the significand always has a leading '1' (except for denormalised numbers, which we'll discuss later). This allows for an extra bit of precision.
Bit Position | Sign | Exponent | Significand |
---|---|---|---|
31-23 | Sign Bit | Exponent (8 bits) | Significand (23 bits) |
22-0 |
In single-precision, the exponent is biased by 127. The bias is added to the actual exponent to determine the final exponent value.
Denormalised numbers (or subnormal numbers) are special cases in floating-point representation. They are used to represent numbers very close to zero. When a number is too small to be represented as a normalised number, it's converted to denormalised form. In denormalised form, the exponent is 0, and the leading bit of the significand is 0. This sacrifices precision but allows for representation of numbers closer to zero.
The normalisation process is still applied to denormalised numbers, but the resulting representation will be a denormalised one.
In practice, normalisation is often implemented using bitwise operations. Shifting the significand left or right can be achieved using left and right shift operators. Adjusting the exponent involves adding or subtracting a value from the exponent field.
The exact code implementation will depend on the programming language and the specific floating-point library being used. However, the underlying principle remains the same: ensure the significand has a leading '1' and adjust the exponent accordingly.