Storage and interpretation of double precision numbers

This is a discussion on Storage and interpretation of double precision numbers within the C Programming forums, part of the General Programming Boards category; I have a few questions about doubles: The way I understand it, a double is a sign bit, followed by ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    452

    Storage and interpretation of double precision numbers

    I have a few questions about doubles:

    The way I understand it, a double is a sign bit, followed by an 11 bit integer exponent, and 53 bit mantissa. The exponent is stored as an unsigned int, and is biased by -1023 when it is interpreted as a double.

    So, to my understanding, in memory a double looks like:

    sign bit - 11 bit UNSIGNED integer - 53 bit mantissa

    Is it true that the exponent is always unsigned until it is interpreted? Or is there even any real difference between the stored bits and the interpreted value besides the fact that the unsigned int is read as a signed one?

    This question is not very clear I don't think.... Hm.

    If I compare the bits of two exponents directly in memory, and one of them is -1 after the bias is applied and the other is 1, will -1 appear to be larger than 1, for example?

    or am I misunderstanding something fundamental here (more likely :P)

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I think you missed the whole "1023" part. The exponent is not stored. The exponent, plus 1023, is stored (as an unsigned number, yes, because quite frankly the stored number by definition can never be negative). So an exponent of -1 is stored as the (actual) number 1022 and +1 is stored as the (actual) number 1024.

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    452
    Right, so a comparison between the two will yield -1 < 1. I was told elsewhere that a comparison of the bits would give a result showing that 1 < -1. Thanks for clearing that up.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,299
    Quote Originally Posted by KBriggs View Post
    I was told elsewhere that a comparison of the bits would give a result showing that 1 < -1.
    Well it will if the one with the larger exponent happens to be holding a negative number (sign bit is set)...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    452
    I am only interested in comparing the 11 exponent bits, the sign bit can be easily handled separately.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    That's referred to as biasing the exponent. You can read more about it here.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21