Long long int not holding my value

May 6, 2012 at 6:18pm
So I need to store a large (trillion) number and am trying to use unsigned long long int.

But when trying to store it, it says that "error: integer constant is too large for "long" type".

Using ULONG_LONG_MAX= 18446744073709551615 which is much larger than my number.

What is happening here?
May 6, 2012 at 6:31pm
Please give us the code that causes this error.
May 6, 2012 at 6:41pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <sstream>
#include <math.h>
#include <cctype>

using namespace std;

int main()

{

       unsigned long long int a = 1000000000000;

}
May 6, 2012 at 6:45pm
Compiles without error on my 64-bit OS machine using LLVM (clang++ front end, V1.1) and g++ (V 4.4.3)
May 6, 2012 at 6:48pm
Compiling with mingw.

Is it because I have a 32 bit system?
May 6, 2012 at 6:53pm
@rozick1

Try defining your variable as unsigned _int64 a;. As long as the number is positive, it works.
May 6, 2012 at 6:54pm
What does this give you?

1
2
3
4
5
6
7
8
#include <limits>
#include <iostream>

int main()
{
 const long long int max_int = std::numeric_limits<long long int>::max();
 std::cout << max_int;
}

May 6, 2012 at 6:57pm
@whitenite1

Same error.
May 6, 2012 at 6:58pm
@Moschops

9223372036854775807
May 6, 2012 at 6:58pm
_int64 is non-standard and I'll be surprised if the MinGW gcc port recognises it.
May 6, 2012 at 7:01pm
It does but only with an extra underscore.
Topic archived. No new replies allowed.