In: Computer Science
Two numbers x and y that are not machine numbers are read into a 32-bit word-length computer. The machine computes to xy2. what sort of relative error can be expected? Assume no underflow or overflow
For Integer values
If numbers x and y are integers then there will be no relative error because computer need not round off or chop the integers for any arithmetic operation, unless underflow or overflow, which according to the question need not be considered.
For floating-point values
We have word length of 32 bits where as much as possible of the normalized floating-point number ±q × 2m must be contained in these 32 bits. Let us take allocation as follows:
sign of q | 1 bit |
sign of m | 1 bit |
|m| | 6 bits |
q | 24 bits |
Calculating relative unit bound error:
Consider a positive number in normalized floating-point for,
x = ±q × 2m, 0.5 ≤ q < 1, |m| ≤ 26 − 1 = 63
Replacing x by its nearest machine number, denoted by fl(x), is a process known as rounding and the error involved is known as round-off error. Writing x in normalized binary notation
x = (0.1a2a3 · · · a20a21a22 · · ·)2 × 2m
the nearest machine number to the left of x (rounding down) on the real number line
xL = (0.1a2a3 · · · a24)2 × 2m
while the nearest machine number to the right of x (rounding up) is
xR = [(0.1a2a3 · · · a24)2 + 2−24] × 2m
The closer of these machine numbers is the one chosen to represent x. If x lies closer to xL than xR, then,
|x − xL| ≤ 0.5 * |xR − xL| = 2−25+m
so that the relative error bound is calculated as
|x − xL| / |x| ≤ (2−25+m / (0.1a2a3 · · ·)2 × 2m) ≤ 2−25 / 2 = 2−24
=>Relative unit error bound will be 2-24 for our machine.
Now consider xy2
For our allocation, we have 6 bits for the representation of 'm', thus 6 digits normalised floating-point number. As a result, x*y*y will have 18 normalised digits which give a relative error of 18*(2-24).