64 bit integer

Jay (22)

Usenet Archive
Joined
Dec 7, 2005
Messages
8
Reaction score
0
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
 

Michiel.Salters

Usenet Archive
Joined
Nov 24, 2005
Messages
273
Reaction score
0
Jay said:
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
 

mlimber

Usenet Archive
Joined
Aug 12, 2005
Messages
2,052
Reaction score
0
Jay said:
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
 

Jay (22)

Usenet Archive
Joined
Dec 7, 2005
Messages
8
Reaction score
0
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 (22)

Usenet Archive
Joined
Dec 7, 2005
Messages
8
Reaction score
0
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?
 

Bronek Kozicki

Usenet Archive
Joined
Sep 21, 2003
Messages
31
Reaction score
0
Jay said:
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.
 

mlimber

Usenet Archive
Joined
Aug 12, 2005
Messages
2,052
Reaction score
0
Jay said:
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
 

James.Mahler

Usenet Archive
Joined
Dec 7, 2005
Messages
2
Reaction score
0
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.
 

mlimber

Usenet Archive
Joined
Aug 12, 2005
Messages
2,052
Reaction score
0
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
 

Clark S. Cox III

Usenet Archive
Joined
Jul 2, 2001
Messages
431
Reaction score
0
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++.
 

Greg (archive)

Usenet Archive
Joined
Mar 9, 2000
Messages
838
Reaction score
0
Jay said:
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 (archive)

Usenet Archive
Joined
Mar 9, 2000
Messages
838
Reaction score
0
mlimber said:
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
 

Jay (22)

Usenet Archive
Joined
Dec 7, 2005
Messages
8
Reaction score
0
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 (22)

Usenet Archive
Joined
Dec 7, 2005
Messages
8
Reaction score
0
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
 

Markus Moll

Usenet Archive
Joined
Sep 30, 2004
Messages
207
Reaction score
0
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
 

Jay (22)

Usenet Archive
Joined
Dec 7, 2005
Messages
8
Reaction score
0
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.
 

Jack Klein

Usenet Archive
Joined
Aug 21, 2000
Messages
3,261
Reaction score
0
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++.
 

Bronek Kozicki

Usenet Archive
Joined
Sep 21, 2003
Messages
31
Reaction score
0
Jay said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top