I thought most modern c and c++ compilers supported some form of 64-bit integers. Try just "long long" instead of "long long int".
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Please post your program -- maybe there is something else wrong with it. I don't have a *nix os so I can't really help you much.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
That value is correct as maximum for signed long long.
What specific compiler are you using?
Look at the include file to see what types and their ranges are available in that compiler.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Try putting "LL" after the literal value, as in:
const long long int biggest_i8 = 9223372036854775807LL;
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Alas, long long int is not a standard type in C++ at the moment. Moreover, the C++ (and C) standard garantees that long number type is not less that ordinar type - that's all (for example, sizeof(long long int) >= sizeof(long int) , but not sizeof(long long) > sizeof(long) ).
Therefore it was a very careless project decision to rely upon non-standardlong long int POD type with huge values range.
There are arbitrary precision integer arithmetics libraries for C++ and C but it seems you need too serious code refactoring to use those libraries (it's easier to move to double type).
If it's a very long (long long;) ) code use Windows+VC++ compiler with 64-bit long long type extension. Regrettably I don't know proper linux compilers with 64-bit long long (ask linux guru)...
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
Doesn't the latest version of g++ support it? Maybe you just need to download the lastest version. GNU is usually pretty good at keeping those compilers up-to-date.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
MosaicFuneral
Posting Virtuoso
1,691 posts since Nov 2008
Reputation Points: 888
Solved Threads: 116
gcc 4.3.0 under Fedora 10 supports the long long. You must put the LL after the large literal.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
The problem here is that g++ knows that only 64 bit can effectively be handled at the processor level. So the authors/steering committee have decided that if long int (which is 8 bytes long) is insufficient then you should be using the gmp (gnu multiple precision library).
Since this is a prerequisite to compile gcc/g++ (well, you can avoid it but it is more work than downloading and compiling gmp). You are likely to have it. If not then http://gmplib.org/ (this site also has the manuals).
It is very easy to use:
#include <iostream>
#include <gmpxx.h>
int main()
{
mpz_class a,b,c;
a="4567890237498712303247829734";
b="4356789023749871231827348234";
c=567423;
std::cout<<"A = "<<a*b*c<<std::endl;
}
Then use g++ testProg.cpp -lgmpxx -lgmp to test it
Note that you use a string to initialize if you initialization is very very big.
You can compare / use it in conjunction with int etc. Note that you need to use a suitable get_xx function to convert back to int. You can check the number is suitable for the conversion as well.
Anyway if you get stuck post a bit of code and I hope we can help. If it is open source (and much of the astronomy code is -- then just the link will do)
StuXYZ
Practically a Master Poster
680 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138
So the authors/steering committee have decided that if long int (which is 8 bytes long)
Where do you get an 8 byte long int? It's 4 bytes everywhere I've seen.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Where do you get an 8 byte long int? It's 4 bytes everywhere I've seen.
A long long int (signed/unsigned) is 8 bytes. cout<<sizeof(long long)
unbeatable0
Junior Poster in Training
90 posts since Sep 2008
Reputation Points: 42
Solved Threads: 13
A long long int (signed/unsigned) is 8 bytes. cout<<sizeof(long long)
Sorry I think I have made a mistake. I only have 64 machines so I get 8 byte. (by default). It you want 8 byte on a 32 bit x86 machine you will need the correct option on your configure line when you build gcc.
The quick way then is to use the gmp.
StuXYZ
Practically a Master Poster
680 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138
A long long int (signed/unsigned) is 8 bytes. cout<<sizeof(long long)
vmanes was correct -- you said a "long int", not long long.
>>I only have 64 machines so I get 8 byte. (by default).
I'm running 64-bit Vista using VC++ 2008 Express and sizeof(long) is 4 bytes. It probably depends also on the compiler.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
I'm sure if you were using VC++, you could point it to the TR1 headers as well.
Now VC++ 2008 supports 64-bitlong long w/o TR1 headers (no such headers in VC++).
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
VC++ 2005 also supports long long int with no special/additional headers.
OP is working in Linux, where current version of gcc also supports long long int. At least as far back as ver 4.1.3.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228