Title

Thursday, 15 January 2015

Float and double - Significand numbers- Mantissa POV?


With Single precision (32 bits): the bits division goes like this :

enter image description here

So we have 23 bits of mantissa/Significand .

So we can represent 2^23 numbers (via 23 bits ) : which is 8388608 --> which is 7 digit long.

BUT

I was reading that the mantissa is normalized (the leading digit in the mantissa will always be a 1) - so the pattern is actually 1.mmm and only the mmm is represented in the mantissa.

for example : look here :

enter image description here

0.75 is represented but it's actually 1.75

Question #1

So basically it adds 1 more precision digit....no ?

If so then we have 8 Significand !

So why does msdn says : 7 ?

enter image description here

Question #2

In double there are 52 bits for mantissa. (0..51)

If I add 1 for the normalized mantissa so its 2^53 possibilites which is : 9007199254740992 ( 16 digits)

and MS does say : 15-16 :

enter image description here

Why is this inconsistency ? am I missing something ?

Answer

The implied leading 1 adds one more binary digit of precision, not decimal.

Answer2

It doesn't add one more decimal digit - just a single binary digit. So instead of 23 bits, you have 24 bits. This is handy, because the only number you can't represent as starting with a one is zero, and that's a special value.

Now, decimal digits versus binary digits is a tricky matter. You're mistaken in your understanding that the precision has anything to do with the 2 ^ 24 figure - that would only be true if you were talking about e.g. the decimal type, which actually stores decimal values as decimal point offsets of a normal (huge-ass) integer.

Just like 1 / 3 cannot be written in decimal (0.333333...), many simple decimal numbers can't be represented in a float precisely (0.2 is the typical example). decimal doesn't have a problem with that - it's just 2 shifted one digit to the right, easy peasy. For floats, however, you have to represent this value as a sum of negative powers of two - 0.5, 0.25, 0.125 ...

No comments:

Post a Comment