Defination - Real numbers are numbers that include fractions/values after the decimal point.
For example, 123.75 is a real number.
Floating point representation
Real numbers are stored in a computer as floating point numbers using a mantissa (m), a base (b) and an exponent (e) in this format:
m X be
Example (in decimal)
This example gives a general idea of the role of the mantissa, base and exponent. It does not fully reflect the computer's method for storing real numbers.
The number 123.75 can be represented as a floating point number. To do this, move all the digits so that the most significant digit is to the right of the decimal point:
123.75 → 0.12375
The number after the decimal point is the mantissa (m).
As this number is written in decimal (denary), the base (b) is 10 .
To work out the exponent (e) count how many decimal places you have moved the decimal point by (in this case three). So we can represent 123.75 in floating point representation as this:
0.12375 x 103
Example (in binary)
In the Higher course, all floating point representation is in binary.
First convert 123.75 to binary:
| 64 | 32 | 16 | 8 | 4 | 2 | 1 | 0.5 | 0.25 |
| 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 |
64 + 32 + 16 + 8 + 2 + 1 + 0.5 + 0.25 = 1111011.11
Key fact
The computer will not store the actual decimal point as part of the floating point number but it is used here for illustrative purposes.
To find the mantissa, move the decimal point to the right of the most significant bit of the mantissa:
1111011.11 → 0.111101111
To calculate the exponent, count how many places the decimal point moved to give the mantissa. In this case the decimal point moved seven places to the left:
So the exponent for our number is 7.
| 4 | 2 | 1 |
| 1 | 1 | 1 |
In binary, the number 7 is 111 as 4 + 2 + 1 = 7
In order to represent 123.75 the mantissa would be 111101111 and the exponent would be 111. This can be thought of as:
0.111101111 x 2111
Sign bit
As well as the mantissa, base and exponent, we have a digit before the decimal point. This is used as a sign bit and is represented in binary as a 0 for positive and a 1 for negative.
How many bits?
There will always be a trade-off between accuracy and range when using floating point notation, as there will always be a set number of bits allocated to storing real numbers:
- increasing the number of bits devoted to the mantissa will improve the accuracy of a floating point number
- increasing the number of bits devoted to the exponent will increase the range of numbers that can be held
In the Higher course, floating point numbers are represented as follows:
- 1 bit for the sign
- 15 bits for the mantissa
- 8 bits for the exponent
