A-level Computing/AQA/Paper 2/Fundamentals of data representation/Floating point errors

From testwiki
Jump to navigation Jump to search

Template:CPTPageNavigationP2



Significant digits

  • What are the drawbacks of using floating point numbers?
  • What errors can you get?

Precision

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.

Rounding errors

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.

Absolute errors

This is the actual number difference between the desired value and the rounded value.

AbsoluteError=|targetNumclosestNum|

Where |a| means: make a positive.
Example 1:
|23.27 – 23.25| = 0.02 absolute error
Example 2:
|23.27 – 23.29| = 0.02 absolute error

Template:CPTExercise Template:CPTQuestion Template:CPTAnswerTab 3.333 - 3.25 = 0.083 Template:CPTAnswerTabEnd Template:CPTQuestion Template:CPTAnswerTab 12.67 - 12.625 = 0.045 Template:CPTAnswerTabEnd

Template:CPTQuestion Template:CPTAnswerTab 1000.1101 = 8.8125, the closest we can get
8.8 - 8.8125 = -0.0125 Template:CPTAnswerTabEnd Template:Robox/Close

Relative error

This is the percentage difference between the desired value and the rounded value.

RelativeError=|targetNumfloatingNum|targetNum*100=AbsoluteErrortargetNum*100

Example:
(23.27 – 23.25) / 23.27 = 0.09%

Template:CPTExercise Template:CPTQuestion Template:CPTAnswerTab

  • 3.333 - 3.25 = 0.083
  • (0.083 / 3.333)*100 = 2.49%

Template:CPTAnswerTabEnd Template:CPTQuestion Template:CPTAnswerTab

  • 12.67 - 12.625 = 0.045
  • (0.045/12.67)*100 = 0.36%

Template:CPTAnswerTabEnd Template:CPTQuestion Template:CPTAnswerTab

  • 1000.1101
  • 8.8 - 8.8125 = 0.0125
  • (0.0125/8.8)*100 = 0.14%

Template:CPTAnswerTabEnd Template:Robox/Close

Cancellation error

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

Underflow

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

Overflow

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

Template:BookCat