Consider the values A = 2.0 x 10^30, B = -2.0 x 10^30, C = 1.0, and the…

2000

Consider the values A = 2.0 x 10^30, B = -2.0 x 10^30, C = 1.0, and the following floating-point computations:

For X:
X := A + B
X := X + C

For Y:
Y := A + C
Y := Y + B

The computations are executed on a computer where floating-point numbers are represented with 32 bits. The values of X and Y will be:

Answer: B. X = 1.0, Y = 0.0In 32-bit floating-point representation, only a limited number of significant digits can be stored. For X: A + B = (2.0 x 10^30) + (-2.0 x 10^30) = 0.0 Then X…

  1. A.

    X = 1.0, Y = 1.0

  2. B.

    X = 1.0, Y = 0.0

  3. C.

    X = 0.0, Y = 1.0

  4. D.

    X = 0.0, Y = 0.0

Attempted by 41 students.

Show answer & explanation

Correct answer: B

In 32-bit floating-point representation, only a limited number of significant digits can be stored.

For X:
A + B = (2.0 x 10^30) + (-2.0 x 10^30) = 0.0
Then X + C = 0.0 + 1.0 = 1.0.

For Y:
A + C = 2.0 x 10^30 + 1.0. The value 1.0 is too small compared with 2.0 x 10^30 to affect the stored 32-bit floating-point result, so the result remains approximately A.
Then Y + B = A + (-A) = 0.0.

Thus X = 1.0 and Y = 0.0. This illustrates that floating-point addition is not associative.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…