edited by
11,816 views
41 votes
41 votes

Consider the values of $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 $X$ and $Y$ will be

  1. $X = 1.0, Y = 1.0$
  2. $X = 1.0, Y = 0.0$
  3. $X = 0.0, Y = 1.0$
  4. $X = 0.0, Y = 0.0$
edited by

4 Answers

Best answer
41 votes
41 votes

Given $32$ bits representation. So, the maximum precision can be $32$ bits (In $32$-bit IEEE representation, maximum precision is $24$ bits but we take the best case here). This means approximately $10$ digits. 

$A = 2.0 \times 10^{30}, C = 1.0$

So, $A + C$ should make the $31$st digit to $1,$ which is surely outside the precision level of $A$ (it is $31$st digit and not $31$st 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.$ 

B choice. 

Sample program if anyone wants to try:

#include<stdio.h>
int main()
{
        float a = 2.0e30;
        float b = -2.0e30;
        float c = 1.0;
        float y = a+c;
        printf("a = %0.25f y = %0.25f\n",a, y);
        y = y + b;
        float x = a + b;
        printf("x = %0.25f\n",x);
        x = x + c;
        printf("x = %0.25f\n",x);
}
edited by
17 votes
17 votes

It is given in the question that "floating point numbers are represented with $32\ bits$"
so from 32 bits we can get  $2^{32} = 4, 294 , 967 , 296$ = total $10$ digits in decimal .
that means 32 bits are equal to 10 decimal digits.


$A = 2.0 \times 10^{30}$ this represents 31 digits and $C = 1.0$ this is 1 digit.

So $A+C =  total\ (31+1) = 31$ digits.(addition in decimal)
A is one 2 followed by thirty 0's = 31 digits and C is 1 digit.
This 31st digit is outside the precision level of A


As we need to do $Y = A + C$, so it does not take the value of $C$.

Y = A is assigned and at max, it takes 10 digits and rest are overflow that's why this addition only return value of A, one extra digit it cannot take
This addition will return the value of A which will be assigned to Y.


So $Y = A+C = A$
and $Y = Y + B = ( 2.0 \times 10^{30} ) + ( - 2.0 \times 10^{30}  ) = 0 .0 $


$X = A+B = ( 2.0 \times 10^{30} ) + ( - 2.0 \times 10^{30}  ) = 0 .0$ 
and $X = X+C = 0.0 + 1.0 = 1.0$ 

$\therefore$ $B$ is the correct option.

edited by
7 votes
7 votes

 " floating point numbers are represented with 32 bits " ..

so from 32 bits we can represent a max of $2^32$-1  = 4, 294 , 967 , 295 which contains total 10 digits in decimal .

that means 32 bits are equivalent to 10 decimal digits .

A = 2.0 *  $10^3$$^0$ = 2000000000000000000000000000000(i.e. 2 followed by 30 zeroes)  it is not a floating point number 

B =-2.0 * $10^3$$^0$ = -2000000000000000000000000000000(i.e. -2 followed by 30 zeroes)  it is not a floating point number 

A,B are represented here in scientific notation but they are not floating point numbers

so they will not be represented by 32 bits but 

$C= 1.0$              it is a floating point number 

it is represented by 32 bits 

X: = A + B

x= (2.0-2.0) * $10^3$$^0$ = 0.0

X = X+C = 0.0 + 1.0 = 1.0 

Y: = A + C

if A is added with C it makes A+C as floating point and assigns it to Y but Y can only store 32 bits or 10 digits due to which A+C will return A only and A will get assigned to Y

Y=2.0 * $10^3$$^0$

and Y = Y + B = ( 2.0 * $10^3$$^0$ ) + ( - 2.0 * $10^3$$^0$  ) = 0 .0 

so 

X = 1.0 Y=0.0

Answer is option(B)

correct me if I am wrong 

0 votes
0 votes
$X :A + B:$

\( A \) and \( B \) are very large numbers, and their difference is relatively small compared to their magnitudes. In 32-bit floating-point representation, this small difference can be lost due to limited precision. Therefore, \( A + B \) is likely to be rounded to \( 0.0 \), resulting in \( X = 0.0 \).

$Y :A + C:$

\( A \) is a very large number, and adding \( 1.0 \) to it won't significantly change its value in 32-bit representation. Therefore, \( Y \) will also be approximately \( 2.0 \times 10^{30} \).

$X :X + C:$

\( X \) is currently \( 0.0 \), so adding \( 1.0 \) to it results in \( X = 1.0 \).

$Y :Y + B:$

\( Y \) is approximately \( 2.0 \times 10^{30} \), and \( B \) is \( -2.0 \times 10^{30} \). Again, due to limited precision, their difference might be lost, resulting in \( Y \) being rounded to \( 0.0 \).

Therefore, the final values are \( X = 1.0 \) and \( Y = 0.0 \).
Answer:

Related questions

38 votes
38 votes
4 answers
1
Kathleen asked Sep 14, 2014
10,928 views
The number $43$ in $2's$ complement representation is$01010101$$11010101$$00101011$$10101011$
37 votes
37 votes
5 answers
2
Kathleen asked Sep 14, 2014
11,428 views
The following arrangement of master-slave flip flopshas the initial state of $P, Q$ as $0, 1$ (respectively). After three clock cycles the output state $P, Q$ is (respect...
35 votes
35 votes
6 answers
3
Kathleen asked Sep 14, 2014
7,025 views
Which functions does NOT implement the Karnaugh map given below? $(w + x) y$$xy + yw$$(w + x) (\bar{w} + y) (\bar{x} + y)$None of t...
41 votes
41 votes
5 answers
4