64 bit integer

Discussion in 'C++' started by Jay, Dec 7, 2005.

  1. Jay

    Jay Guest

    Hello, I am sure this has a quick and easy solution but I can't find
    it.

    I need to store 19 '9's in an integer which means i need an unsigned 64
    bit
    integer.
    in Visual Studio the code would be:

    __int64 test = 9999999999999999999;

    I am using g++ version 3.3.5(suse 9.3) and have tried both:

    unsigned long long test = 999999999999999999;
    and:
    uint64_t test = 9999999999999999999;

    both have this compile error using the command "g++ test.cpp"
    test.cpp:5: error: integer constant is too large for "long" type

    Am I forgeting to include something or not passing an option to g++, or
    is
    there another way to do 64 bit integer storage?

    Thank you for your help
     
    Jay, Dec 7, 2005
    #1
    1. Advertising

  2. Jay

    Guest

    Jay wrote:
    > Hello, I am sure this has a quick and easy solution but I can't find
    > it.
    >
    > I need to store 19 '9's in an integer which means i need an unsigned 64
    > bit integer. in Visual Studio the code would be:
    >
    > __int64 test = 9999999999999999999;


    The double underscore is a giveaway that this isn't C++, but a
    Microsoft
    extension.

    > I am using g++ version 3.3.5(suse 9.3) and have tried both:
    >
    > unsigned long long test = 999999999999999999;
    > and:
    > uint64_t test = 9999999999999999999;
    >
    > both have this compile error using the command "g++ test.cpp"
    > test.cpp:5: error: integer constant is too large for "long" type


    Reasonable, by the standard rules it may indeed reject the code. If
    you need an GCC extension to C++, you should ask in a GCC group.

    HTH,
    Michiel Salters
     
    , Dec 7, 2005
    #2
    1. Advertising

  3. Jay

    mlimber Guest

    Jay wrote:
    > Hello, I am sure this has a quick and easy solution but I can't find
    > it.
    >
    > I need to store 19 '9's in an integer which means i need an unsigned 64
    > bit
    > integer.

    [snip]

    Or you could use a number class with arbitrary precision. The sizes of
    the various built-in integral types are platform-dependent, so you'll
    want to check with your OS/compiler documentation.

    Cheers! --M
     
    mlimber, Dec 7, 2005
    #3
  4. Jay

    Jay Guest

    So is there no way to do this in C++ without using an extension?
    If this is the wrong group for this question, do you happen to know
    which group would be more appropriate?

    Thank you
     
    Jay, Dec 7, 2005
    #4
  5. Jay

    Jay Guest

    I know that the sizes of int, long etc are platform-dependent and I
    know that they are not big enough on my platform, I am looking for a
    datatype that guarentees me 64bits on any platform. I don't really want
    to have to include non-standard libraries, but is there a number class
    with arbitrary precision that you would suggest?
     
    Jay, Dec 7, 2005
    #5
  6. Jay <> wrote:
    > uint64_t test = 9999999999999999999;
    >
    > both have this compile error using the command "g++ test.cpp"
    > test.cpp:5: error: integer constant is too large for "long" type


    try:

    uint64_t test = 9999999999999999999LL;


    B.
     
    Bronek Kozicki, Dec 7, 2005
    #6
  7. Jay

    mlimber Guest

    Jay wrote:
    > I know that the sizes of int, long etc are platform-dependent and I
    > know that they are not big enough on my platform, I am looking for a
    > datatype that guarentees me 64bits on any platform.


    No such thing with built-in types. C++ compilers can be standard
    compliant on 8-bit machines, which implies that no built-in type
    *necessarily* supports 64 bits.

    > I don't really want
    > to have to include non-standard libraries, but is there a number class
    > with arbitrary precision that you would suggest?


    Check out:

    http://www.oonumerics.org/oon/

    Cheers! --M
     
    mlimber, Dec 7, 2005
    #7
  8. Jay

    mlimber Guest

    mlimber wrote:
    > Jay wrote:
    > > I don't really want
    > > to have to include non-standard libraries, but is there a number class
    > > with arbitrary precision that you would suggest?

    >
    > Check out:
    >
    > http://www.oonumerics.org/oon/


    See also

    http://www.swox.com/gmp/

    Cheers! --M
     
    mlimber, Dec 7, 2005
    #8
  9. Jay

    Guest

    unsigned long long a = 9999999999999999999LLU; is the right way to do
    it. If you don't say it's unsigned you get warnings because it's too
    large.

    That works fine for 64 bit numbers on 32 bit machine.
     
    , Dec 7, 2005
    #9
  10. Jay

    Jay Guest

    Thanks, I just forgot the LLU on the end of a non-int constant
     
    Jay, Dec 7, 2005
    #10
  11. Jay

    mlimber Guest

    wrote:
    > unsigned long long a = 9999999999999999999LLU; is the right way to do
    > it. If you don't say it's unsigned you get warnings because it's too
    > large.
    >
    > That works fine for 64 bit numbers on 32 bit machine.


    long long is a compiler extension. It is not standard and will not work
    on all platforms or compilers. long is guaranteed to be at least 32
    bits by the standard; that's as big as it gets as far as the standard
    is concerned (for now).

    Cheers! --M
     
    mlimber, Dec 7, 2005
    #11
  12. On 2005-12-07 11:23:19 -0500, said:

    > unsigned long long a = 9999999999999999999LLU; is the right way to do
    > it.


    That is, if your C++ compiler supports 'long long' as an extension.
    While many do, remember that 'long long' is a feature of C99, *not* of
    C++.

    --
    Clark S. Cox, III
     
    Clark S. Cox III, Dec 7, 2005
    #12
  13. Jay

    Greg Guest

    Jay wrote:
    > Hello, I am sure this has a quick and easy solution but I can't find
    > it.
    >
    > I need to store 19 '9's in an integer which means i need an unsigned 64
    > bit
    > integer.
    > in Visual Studio the code would be:
    >
    > __int64 test = 9999999999999999999;
    >
    > I am using g++ version 3.3.5(suse 9.3) and have tried both:
    >
    > unsigned long long test = 999999999999999999;
    > and:
    > uint64_t test = 9999999999999999999;
    >
    > both have this compile error using the command "g++ test.cpp"
    > test.cpp:5: error: integer constant is too large for "long" type
    >
    > Am I forgeting to include something or not passing an option to g++, or
    > is
    > there another way to do 64 bit integer storage?


    Yes. This is how the declaration should look:

    unsigned long long test = 999999999999999999ULL;

    long long constants require an LL or ULL type designator. Although long
    longs are not yet officially part of the C++ language they will be
    added in the next revision.

    Greg
     
    Greg, Dec 7, 2005
    #13
  14. Jay

    Greg Guest

    mlimber wrote:
    > wrote:
    > > unsigned long long a = 9999999999999999999LLU; is the right way to do
    > > it. If you don't say it's unsigned you get warnings because it's too
    > > large.
    > >
    > > That works fine for 64 bit numbers on 32 bit machine.

    >
    > long long is a compiler extension. It is not standard and will not work
    > on all platforms or compilers. long is guaranteed to be at least 32
    > bits by the standard; that's as big as it gets as far as the standard
    > is concerned (for now).


    long longs are part of the C99 standard and will be in the next
    revision of the C++ standard.

    It is C99, and not C++, that specifies the size of integer types. C++
    makes no guarantee that any integer type will be larger than a byte.

    Greg
     
    Greg, Dec 7, 2005
    #14
  15. Jay

    Jay Guest

    Well I think I will go with the extension that doesn't require me to go
    find another class to add to my code which should be simple for a
    programing language as powerful as c++. I am disappointed that
    everything I want to do for this project is an extension of c++. Maybe
    I
    should just report that the project is coded in a custom language. At
    least it's working with long long, hopefully whatever commitee decides
    on c++ standards will help me out someday, but until then, I'm going to
    be a fan of extensions
     
    Jay, Dec 7, 2005
    #15
  16. Jay

    Jay Guest

    Good to hear, I'm guessing that if it's known to be part of the next
    revision, the compilers will have already put it in. So nothng to
    really worry about there
     
    Jay, Dec 7, 2005
    #16
  17. Jay

    Markus Moll Guest

    Hi

    Jay wrote:

    [about long long]
    > Good to hear, I'm guessing that if it's known to be part of the next
    > revision, the compilers will have already put it in. So nothng to
    > really worry about there


    But following the reasoning of your recent post elsewhere in this thread,
    you would soon start crying that there is no type long long long that is
    guaranteed to be at least 96 or 128 bits long. And if one would add this,
    at some point the need for an 256 bits type would come up. A never-ending
    story...

    If you're targeting a specific platform, you're fine using whatever your
    compiler offers you (i.e. extensions).

    If you want a program that is standard compliant and thus
    platform-independent, you will have to use some sort of arbitrary precision
    library. (or at least a library that defines some sort of 64-bit integer (I
    think boost does?))

    If you're about to argue that this should be part of the standard library:
    I'm with you there.

    But please don't blame the language.

    cheers
    Markus
     
    Markus Moll, Dec 7, 2005
    #17
  18. Jay

    Jay Guest

    first about your story. I hope you are not naive enough to think
    anything in software should have an ending.
    The fact that you are "with me" on the argument that it should be in
    the standard shows that you agree that
    the language should change as times change.

    Since you brought reasoning how do you logically say that the language
    should have something it doesn't, and don't blame the language?


    The reason I wanted, and apparently was crying over, a 64 bit int
    only has a little to do with being a baby.
    I am just trying to grab a value from a database, a value that is a 64
    bit number. it's one variable in my program that I get and then do a
    couple
    computations on. Forgive me if I didn't want to use your precious
    boost library and add an extra file to my project for 1 variable. The
    point is that
    the database is a pretty old database and I figured that if it was easy
    for the database people to do years ago it should be cake today.
    Adding a library is less
    than cake. long long is a little closer to cake. It being a standard
    and documented would be cake. I just want cake or as close to it as I
    can get.

    That being said I don't know why you posted. I thought "Good to hear"
    was a positive notion.
     
    Jay, Dec 7, 2005
    #18
  19. Jay

    Jack Klein Guest

    On 7 Dec 2005 08:23:19 -0800, wrote in
    comp.lang.c++:

    > unsigned long long a = 9999999999999999999LLU; is the right way to do
    > it. If you don't say it's unsigned you get warnings because it's too
    > large.
    >
    > That works fine for 64 bit numbers on 32 bit machine.


    Except that there is no long long type, signed or unsigned, in
    standard C++. It is standard in C since 1999, but an extension in
    C++.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Dec 8, 2005
    #19
  20. Jay <> wrote:
    > the database is a pretty old database and I figured that if it was
    > easy for the database people to do years ago it should be cake today.


    hahahaha. Tell me more about fixed point decimal arithmetic in C++ .


    B.
     
    Bronek Kozicki, Dec 8, 2005
    #20
    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. Replies:
    3
    Views:
    1,830
    Timothy Bendfelt
    Jan 19, 2007
  2. Imayam

    How to use 64 bit integer in 16 Bit Dos ?

    Imayam, Jun 15, 2006, in forum: C Programming
    Replies:
    3
    Views:
    418
    Mark McIntyre
    Jun 15, 2006
  3. Replies:
    9
    Views:
    1,033
    Juha Nieminen
    Aug 22, 2007
  4. xyz
    Replies:
    2
    Views:
    843
  5. Jeff.M
    Replies:
    6
    Views:
    199
    Lasse Reichstein Nielsen
    May 4, 2009
Loading...

Share This Page