Consider the values of and the sequence
X:= A + B Y:= A + C X:= X + C Y:= Y + B
executed on a computer where floating point numbers are represented with bits. The values for and will be
View worked solution
Answer: B
In a 32-bit single-precision floating-point representation (such as IEEE 754), the significand has 24 bits of precision, which offers approximately 7 decimal digits of precision.
For :
X := A + B: Since and have equal magnitudes but opposite signs, they cancel out exactly:X := X + C: Adding gives:
For :
Y := A + C: We attempt to add and . Because their magnitudes differ by 30 orders of decimal magnitude (which vastly exceeds the 7-digit precision limit of 32-bit floats), the smaller value is rounded off to zero during alignment. Thus:Y := Y + B: Adding gives:
Therefore, the final values are and , which corresponds to Option B.
Free practice · Your answers on this page are not saved.
