C++: integer constant is too large for "long" type

Jo Deni

Usenet Archive
Joined
Aug 9, 2007
Messages
1
Reaction score
0
Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine.
So what can I do to fix the problem?

Thanks,
Jo
 

soxmax

Usenet Archive
Joined
Nov 29, 2005
Messages
6
Reaction score
0
Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine.
So what can I do to fix the problem?

Thanks,
Jo

try "long long" or "__int64" or "long double" instead of "double"
 

Just Me

Usenet Archive
Joined
Sep 18, 2000
Messages
258
Reaction score
0
Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine. So what can I do to fix the problem?

Thanks,
Jo

don't you mean

double X = 1.0e10;

The compiler is trying to parse 10000000000 as an integer constant and it cannot do so.
 

Kai-Uwe Bux

Usenet Archive
Joined
Jun 5, 2004
Messages
3,283
Reaction score
0
Jo said:
Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine.
So what can I do to fix the problem?

Try

double X = 10000000000.0;

Best

Kai-Uwe Bux
 

tony_in_da_uk

Usenet Archive
Joined
Aug 12, 2005
Messages
116
Reaction score
0
double X = 10000000000;
The execution for X = 10^9 worked fine.
So what can I do to fix the problem?

Hi Jo,

I think your compiler would first parse all elements in your program, and consider the number to be a 32 bit integer (at which time there's a problem), then later try to "promote" it to a double for assignment into X. Just write the number as a floating pointer constant to begin with: 1E10 or 1000000000000.0.

Tony
 

Steve (archive)

Usenet Archive
Joined
Jan 19, 2000
Messages
1,088
Reaction score
0
Folks,
I'm a newbie here (and with C++).
While executing a C++ program I'm getting the following message

error: integer constant is too large for "long" type

and here is the offending line in my code

double X = 10000000000;

(X is equal to 10^10)

The execution for X = 10^9 worked fine.
So what can I do to fix the problem?

Thanks,
Jo

10000000000 is trying to be a literal 'int', which is implicitly converted to the double X. You get the error as 10000000000 is too large for a 32 bit int. If you use:

double X = 10000000000.0;

it should be fine.

Steve.
 

Old Wolf

Usenet Archive
Joined
Dec 10, 2003
Messages
2,265
Reaction score
0
double X = 10000000000LL;

LL is not defined in the current C++ standard.
Your compiler might support it as an extension,
but it would be better to use 1E10 or 10000000000.0 .
 

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