Real Numbers: Errors
- what are the drawbacks of using floating point numbers
- what errors can you get?
When using floating point numbers you have to balance the range and the precision of numbers. That is whether you want to have a very large range of values or you want a number that is very precise down to a large number of decimal places. This means that you are going to always weigh up how many digits should be used for the mantissa and how many should be used for the exponent. In summary:
- If you want a very precise number use more digits for the mantissa and less for the exponent as this will allow for more decimal places
- If you want a large range of numbers use more digits for the exponent and less for the mantissa.
When we try to represent some numbers sometimes we can't within the space we have been given, for example trying to write down 1/3 = 0.33333333; you see what I mean? With floating point numbers you can't always get perfect precision and sometimes we suffer errors.
Feed this equation into google:
999999999999999 - 999999999999998
The browser will perform a floating point calculation and give you the answer of 0!
So recognising that we can have rounding errors with floating point numbers we'll take a look at the different errors that might be caused. The following number wants to be represented in binary 23.27, the closest we get is 23.25
This is the actual number difference from the desired value and the rounded value
targetNum - closestNum = Absolute Error 23.27 – 23.25 = 0.02 absolute error
3.333 - 3.25 = 0.083
12.67 - 12.625 = 0.045
1000.1101 = 8.8125, the closest we can get
This is the percentage difference between the desired value and the rounded value
((targetNum - floatingNum)/targetNum)*100 = Relative Error (23.27 – 23.25) / 23.27 = 0.09%
Adding a very small number to a very large number makes no difference to the large number, equations involving very large or small numbers will give you incorrect results. The web search engine example above is a good demonstration of this:
999999999999999 - 999999999999998 = 0
You might also see something like this:
999999999999999 - 1 = 0
When a number or the result of an equation is too small, you might not have enough digits in your mantissa and exponent to show it. In the following example the number would register as 0
Try and show 0.0000000000000000000000000001 in 12 bit FP
When the result of a sum is too large to be represented by your number system you might run out of space to represent it and end up storing a much smaller number
Try and show 99,999,999,999,999,999,999 in 12 bit FP