Data representation · A level · OCR H446 1.4.1, AQA 7517 4.5.4.5, Eduqas A500QS 2.3 · about 30 min
Rounding errors, absolute and relative error, range against precision, overflow and underflow, with a real sensor reading.
[1 mark]A true value of 2.7 is stored as 2.625. What is the absolute error?
[1 mark]A true value of 2.7 is stored as 2.625. What is the relative error as a percentage, to 2 decimal places?
[1 mark]A floating point format keeps 12 bits in total. The mantissa is given more bits and the exponent fewer. What changes?
[1 mark]What is underflow?
[1 mark]Why can 0.1 not be stored exactly in binary floating point?
[1 mark]What does this program print?
a = 0.1 + 0.2 print(a == 0.3) print(abs(a - 0.3) < 1e-9)
The robot faces a wall. Read distance() once (it returns centimetres) and convert it to metres. Store the metres in a byte of unsigned fixed point with all 8 bits after the point: the stored whole number is int(metres * 256), which truncates. Then print exactly these five lines, calculating every value:
- reading: <metres> m, the metres as Python prints the float
- stored: <bits>, the stored whole number as 8 binary digits (you may use format(q, "08b"))
- stored value: <value> m, the stored whole number divided by 256
- absolute error: <error> m, the absolute error, then round(error, 7)
- relative error: <percent>%, the relative error as a percentage, then round(percent, 2), with no space before the %
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
metres = distance() / 100
print("reading:", metres, "m")Plan your program here, then type it in and press Run.