Skip to main content

GATE CSE 2000Digital Logic › Number Systems & RepresentationVerified

GATE CSE 2000 PYQ: Consider the values of A = 2.0 × 1 0 30 , B = − 2.0 × 1 0 30 , C = 1.0 , A = 2.0 \times 10^{30}, B = -2.0…

Consider the values of A=2.0×1030,B=−2.0×1030,C=1.0,A = 2.0 \times 10^{30}, B = -2.0 \times 10^{30}, 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 XX and YY will be

  1. A
    X=1.0,Y=1.0X = 1.0, Y = 1.0
  2. B
    X=1.0,Y=0.0X = 1.0, Y = 0.0
    Correct answer
  3. C
    X=0.0,Y=1.0X = 0.0, Y = 1.0
  4. D
    X=0.0,Y=0.0X = 0.0, Y = 0.0

Answer

(B) X = 1.0 , Y = 0.0 X = 1.0, Y = 0.0 X = 1.0 , Y = 0.0

Approach

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.