GATE | GATE-CS-2000 | Question 37
Consider the values A = 2.0 x 1030, B =-2.0 x 1030, C= 1.0, 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 X and Y will be
(A) X = 1.0, Y = 1.0
(B) X = 1.0, Y = 0.0
(C) X = 0.0, Y = 1.0
(D) X = 0.0, Y = 0.0
Explanation: Given 32 bits representation. So, the maximum precision can be 32 bits.
Therefore, A + C should make the 31st digit to 1, which is surely outside the precision level of A (it is 31st digit and not 31st bit). So, this addition will just return the value of A which will be assigned to Y.
So, Y + B will return 0.0 while X + C will return 1.0.
Note that there is difference in 2000 and 2*10^3 representation. The result is depends on available number of digits for magnitude part. We can not adjust magnitude in exponent part.
So, option (B) is correct.
This explanation has been contributed by Piyush Doorwar.
Quiz of this Question