format of double and __int64

Discussion in 'C Programming' started by Jayesh, Nov 28, 2005.

  1. Jayesh

    Jayesh Guest

    Hi,
    How is a double value stored in 8 bytes ? Or what is the format ?
    How is it different from __int64 ? How is __int64 stored in 8 bytes.
    Please do reply.

    regards,
    Jayesh
    Jayesh, Nov 28, 2005
    #1
    1. Advertising

  2. Jayesh

    Richard Bos Guest

    "Jayesh" <> wrote:

    > How is a double value stored in 8 bytes ? Or what is the format ?


    Only your implementation's documentation can tell you. In fact, only
    your docs can tell you _whether_ a double is stored in 8 bytes, let
    alone how.

    > How is it different from __int64 ? How is __int64 stored in 8 bytes.


    There is no such thing as an __int64 in ISO C, but where it is an
    extension it probably is an integer type. double is a floating point
    type. The two are very different. Integer types are stored as a number
    of value bits, a sign bit if it's a signed type, and possibly a number
    of padding bits. Floating point types are stored as a sign bit
    (always!), a mantissa, and an exponent.

    > Please do reply.


    No. Won't. Refuse to. So there.

    Richard
    Richard Bos, Nov 28, 2005
    #2
    1. Advertising

  3. "Jayesh" <> writes:

    > Hi,
    > How is a double value stored in 8 bytes ?


    First byte first, last byte last, and everyting else in between.

    How a double is stored can vary from one implementation to the
    other, and it doesn't even have to be 8 bytes (whatever a byte
    means...)

    Or what is the format ? In printf "%f" or "%g" perhaps?

    > How is it different from __int64 ?


    There is no type named __int64 in C. (At least not in C90). Anyway,
    a 64 bit integer would store integer value, and double floating
    point values, so the same bit pattern would most likely represent
    different values. One exception might be zero, which might be
    represented as all bits zero both for integers and floating point
    values, but even that is not guarantied.

    /Niklas Norrthon
    Niklas Norrthon, Nov 28, 2005
    #3
  4. > How is a double value stored in 8 bytes ?

    Who says a double takes 8 bytes? That is not guaranteed, although
    it is a popular implementation.

    >Or what is the format ?


    Any format the implementation wants. The double-you aitch ay tee
    format is not particularly popular.

    >How is it different from __int64 ?


    double is a type in standard C. __int64 is not.

    >How is __int64 stored in 8 bytes.


    Types that do not exist aren't stored.

    Gordon L. Burditt
    Gordon Burditt, Nov 28, 2005
    #4
  5. Jayesh

    Jayesh Guest

    Thanks Richard.
    Ok, so double is a floating poind type and is stored as sign
    bit,mantissa and an exponent. So for a double value is there any fixed
    format like these many bits for mantissa and these many bits for
    exponent ?
    Similarly how is the long long variable stored ? Is it a sign bit
    followed by the value bits ?
    ( I use visual c++ compiler or cc or CC and always confuse with whether
    the type belongs to C or C++ :( )

    // Jayesh
    Jayesh, Nov 29, 2005
    #5
  6. On 29 Nov 2005 01:42:13 -0800, in comp.lang.c , "Jayesh"
    <> wrote:

    >Thanks Richard.
    >Ok, so double is a floating poind type and is stored as sign
    >bit,mantissa and an exponent. So for a double value is there any fixed
    >format like these many bits for mantissa and these many bits for
    >exponent ?


    No. However many C implementations will use IEEE 754 format.

    > Similarly how is the long long variable stored ? Is it a sign bit
    >followed by the value bits ?


    Whatever is most convenient for the platform. Typically it might well
    be as you describe, but as far as I know, C makes no requirements.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Nov 29, 2005
    #6
  7. Jayesh

    Eric Sosman Guest

    Jayesh wrote On 11/29/05 04:42,:
    > Thanks Richard.
    > Ok, so double is a floating poind type and is stored as sign
    > bit,mantissa and an exponent. So for a double value is there any fixed
    > format like these many bits for mantissa and these many bits for
    > exponent ?


    The C Standard does not guarantee any particular
    values. However, the Standard requires the implementation
    to document its values through macros defined in <float.h>.
    You seem to be interested in FLT_RADIX, DBL_MANT_DIG,
    DBL_MIN_EXP, and DBL_MAX_EXP.

    --
    Eric Sosman, Nov 29, 2005
    #7
  8. Mark McIntyre <> writes:
    > On 29 Nov 2005 01:42:13 -0800, in comp.lang.c , "Jayesh"
    > <> wrote:

    [...]
    >> Similarly how is the long long variable stored ? Is it a sign bit
    >>followed by the value bits ?

    >
    > Whatever is most convenient for the platform. Typically it might well
    > be as you describe, but as far as I know, C makes no requirements.


    Actually, there are some requirements. Since long long is a signed
    type, it's guaranteed to be represented as one of two's-complement,
    one's-complement, or signed-magnitude. There are also some
    requirements about the value bits matching between any signed integer
    type and the corresponding unsigned type. And there be padding bits
    that don't contribute to the value and/or that can introduce trap
    representations.

    But for the most part, you don't really need to know. Most operators
    are defined to work on the values of the operands, not on their
    representation.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Nov 29, 2005
    #8
  9. Jayesh

    Joe Wright Guest

    Jayesh wrote:
    > Hi,
    > How is a double value stored in 8 bytes ? Or what is the format ?
    > How is it different from __int64 ? How is __int64 stored in 8 bytes.
    > Please do reply.
    >
    > regards,
    > Jayesh
    >

    You've received all valid responses above this one. C won't give you the
    answer. The double is stored in 8 bytes (64 bits) on my system too.
    Something like this..

    (64-bit double)
    6 5 4 3 2 1
    3210987654321098765432109876543210987654321098765432109876543210
    - 1-bit sign (1 == negative)
    ----------- 11-bit exponent (unsigned)
    53-bit mantissa -----------------------------------------------------

    I hope this doesn't wrapup in your newsreader or that you can otherwise
    straighten it out.

    This is really Off Topic in clc. Shame on me.

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
    Joe Wright, Nov 29, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Tsiombikas (Nuclear / the Lab)

    Re: Different results if compared as double or __int64?

    John Tsiombikas (Nuclear / the Lab), Jun 30, 2003, in forum: C++
    Replies:
    1
    Views:
    426
    Victor Bazarov
    Jun 30, 2003
  2. Vivi
    Replies:
    2
    Views:
    5,991
    ES Kim
    Aug 25, 2003
  3. Tim Clacy

    __int64 vs. long long

    Tim Clacy, Nov 10, 2003, in forum: C++
    Replies:
    8
    Views:
    825
    Rolf Magnus
    Nov 10, 2003
  4. Sydex
    Replies:
    12
    Views:
    6,483
    Victor Bazarov
    Feb 17, 2005
  5. Matt Whelan

    SWIG and __int64

    Matt Whelan, Aug 14, 2003, in forum: Python
    Replies:
    2
    Views:
    551
    Matt Whelan
    Aug 15, 2003
Loading...

Share This Page