For a rational number 1/3
below is the floating point representation(64 bit) of decimal expansion 0.3333333....
As per the above bit structure, I would like to interpret the value of exponent(11 bits) and value of fraction(52 bits).
exponent has 11 bits. How do I interpret exponent value?
fraction has 52 bits. Here 0101 is decimal 5
. Am not sure if we captured fractional part 33333333... of decimal expansion? To capture fractional part am I suppose to expect 0011
pattern instead of 0101
. How do I interpret fractional part?
Asked By : overexchange
Answered By : Yuval Filmus
The fractional part is in binary: $(0.01010101\ldots)_2 = (0.333333\ldots)_{10}$. To convince yourself of this, try multiplying the binary $0.0101010101\ldots$ by $3$: you will get $0.111111\ldots = 1$. In a similar way, the decimal $0.0101010101\ldots$ equals $1/99$.
The mantissa (fractional part) in fact has an implicit $1.$ in front, so it actually equals $(1.01010101\ldots)_2 \approx 4/3$. The exponent should therefore be $-2$, since $1/3 = 4/3 \cdot 2^{-2}$. The exponent itself is stored with an offset of $1024$ (or more generally, $2^{w-1}$, where $w$ is the width of the exponent field), that is, instead of $-2$ we actually store $1022$, which in binary reads $01111111101$.
You should note that the floating point number doesn't represent $1/3$ exactly, rather a number pretty close to $1/3$. The only numbers representable exactly in floating point (given enough precision) are dyadic numbers, which are numbers of the form $A/2^B$ (for integer $A,B$).
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/39789
0 comments:
Post a Comment
Let us know your responses and feedback