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 32 bits. The values for and will be
GATE CSE 2000Digital Logic › Number Systems & RepresentationVerified
(B) X = 1.0 , Y = 0.0 X = 1.0, Y = 0.0 X = 1.0 , Y = 0.0
The key is that 32-bit floating-point representation has limited precision. Although A and B are large $(≈2×10^30)$, C=1 is many orders of magnitude smaller. Near $2×10^30$, consecutive representable floating-point numbers are separated by a huge gap (the unit in last place, ULP, is about $10^23$ for IEEE single precision). Therefore adding 1 to such a large number is rounded away and leaves the number unchanged. Thus Y := A + C stores essentially A, and later Y + B cancels to 0. Meanwhile X := A + B gives exactly 0 because A and B have the same magnitude and opposite signs, so X := X + C becomes 1.
Floating-point precision, not exact real arithmetic, governs the result. The magnitude of A makes adding 1 irrelevant, so the C term added to A is lost. The operations A+B and later A+(-A) cancel exactly, while 0.0+1.0 gives 1.0. Thus the only consistent option is B: X=1.0, Y=0.0.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.