2.8k views

The following is a scheme for floating point number representation using 16 bits.

 Bit Position 15 14 .... 9 8 ...... 0 s e m Sign Exponent Mantissa

Let s, e, and m be the numbers represented in binary in the sign, exponent, and mantissa fields respectively. Then the floating point number represented is:

$$\begin{cases}(-1)^s \left(1+m \times 2^{-9}\right) 2^{e-31}, & \text{ if the exponent } \neq 111111 \\ 0, & \text{ otherwise} \end{cases}$$

What is the maximum difference between two successive real numbers representable in this system?

1. $2^{-40}$
2. $2^{-9}$
3. $2^{22}$
4. $2^{31}$

First of all this is one of the best question.

Let us do our analysis in decimal system -

Let we us have 1-Digit Mantissa and 2-Digit Exponent then Mantissa range $-9$ to $9$, and 2-Digit Exponent range $0$ to $100$.

Now possible numbers are $-900, -800 ...... -1, 0, 1, 2 ....10, 20, 30,...800, 900$

It could be observed clearly that max difference between two consecutive number will be max(100) when exponent value is max. Similarly min difference between two consecutive number will be minimum(1) when exponent value is least.

Same principle could be used in the mentioned question.

ping @Puja Mishra, @Shivam Chauhan, @Manu Thakur, @Anu007,  @Hemant Parihar, @ sushmita,  @VS  @Shweta Nair @Krish__,  @Ashwin Kulkarni @reena_kandari  and @srestha ji.

Maximum difference between two successive real number will occur at extremes. This is because numbers are represented upto mantissa bits and as the exponent grows larger, the difference gets multiplied by a larger value. (The minimum difference happens for the least positive exponent value).
Biasing will be done by adding 31 as given in question. So, actual value of exponent will be represented value - 31. Also, we can not have exponent field as all 1's as given in question (usually taken for representing infinity, NAN etc). So, largest value that can be stored is 111110 = 62.
Largest number will be $1.111111111 \times 2^{62-31} = \left(2 - 2^{-9}\right) \times 2^{31}$
Second largest number will be $1.111111110 \times 2^{62-31} = \left(2 - 2^{-8}\right) 2^{31}$
So, difference between these two numbers $= \left(2 - 2^{-9}\right) \times 2^{31} - \left(2 - 2^{-8}\right) \times 2^{31}\\= 2^{31} \left[\left(2 - 2^{-9}\right) - \left(2 - 2^{-8}\right) \right] \\= 2^{31} \left[ 2^{-8} - 2^{-9} \right] \\= 2^{31} \times 2^{-9} = 2^{22}$
edited
Why not just take m= 0 1st time  and m=1 second time. while exponent is 62 .

is it neccesry to take two maximum number. B/c b/w any two no. difference will be same na.
Yes, it is necessary to take the top 2 maximum numbers as the question is asking about two successive real numbers and they will only give the maximum difference.
What of we take 0's from both sides.+0 and -0??I know its silly question,but does this count as successive real number beacause in floating point we have diffferent representation for both which differ by sign.If i draw on number line then after -0 i will got to -ve underflow which will be rounded to -0.But still does this count as two successive numbers?
No, they donot count as two successive numbers. Although one can represent +0 and -0 by floating point but they are exactly same on number line.
Even if you take m = 3 and m = 2, the answer will be the same.No need to take extreme numbers.
@Ashish  nice explanation.. Thanks :)

The gap between two succesive numbers is small towards the minimum value and maximu towards the maximum value.

Fist Maximum:

 0(sign) 111110 (Biased Exponent) 111111111 mantissa

Second Maximum

 0(sign) 111110 (Biased Exponent) 111111110 mantissa

E=62 that is biassed exponent since said not all 1's .

DIfference   = (1+1-2-9)*2E-31 - (1+1-2-8)*2E-31

=(2-2-9)*2E-31 - (2-2-8)*2E-31

= (2-2-9)*262-31 - (2-2-8)*262-31

=231 * [(2-2-9) - (2-2-8) ]

=222 should be the ans.

If we had to find minimum difference between two successive real number..then we will follow thi...am i right?

Fist Minimum:

 1(sign) 111110 (Biased Exponent) 111111111 mantissa

Second Minimum

 1(sign) 111110 (Biased Exponent) 111111110 mantissa

Difference = first minimum - second minimum

Biased exponent should be all 0's ....and mantissa having all 0's for first minimum and for second minimum....all 0's except least significant bit....
OK got it

.thanku.

My previous approach will again give the maximum difference considering -ve real number

Gabbar ,

The gap between two succesive numbers is small towards the minimum value and maximum towards the maximum value.

The max difference is dictated by the exponent , which in this case = 62 , but I didnot get the part why does the mantissa have to be 111111111 and 111111110 ,

As any two succesive numbers has difference of 1 ( 10 - 9 = 1) , so if take any two successive mantissas their difference will always be 000000001.

So only E = 62 should determine the max difference right , as the difference remains constant

Where am I going wrong ?

Largest positive number m all 1's exponent=111110=62

Second largest number m 111111110 exponent=111110=62

Difference=231(2-29-2+2-8)=231*2-9=222

Exponent grows and makes no. larger, so we take adjacent values at extremes. Exponent have to be taken with all 1's except LSB as 0(as all 1's makes no. 0)

 Sign(1 bit) Exponent(6 bits) Mantissa(9 bits) 1st largest no 0=>+ve 111110=>(62)10 111111111=>(511)10 2nd large no 0=>+ve 111110=>(62)10 111111110=>(510)10

diff. = [(1+511*2-9)262-31]   -  [(1+510*2-9)262-31]
= [1+ 511*2-9 - 1 - 510*2-9 ] 262-31
=
[1* 2-9]  262-31

= 2-9+62-31 = 222

edited

largest value = 231+511.222

2nd largest value = 231+510.222

so largest difference between them = 222

C . $2^{22}$