473,246 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

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

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

Aug 10 '07 #1
7 7410
On Aug 9, 9:01 pm, Jo Deni <joachim_denin...@web.dewrote:
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"

Aug 10 '07 #2
On Thu, 09 Aug 2007 20:01:44 -0700, Jo Deni wrote:
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.
Aug 10 '07 #3
Jo Deni wrote:
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
Aug 10 '07 #4
On Aug 10, 12:01 pm, Jo Deni <joachim_denin...@web.dewrote:
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

Aug 10 '07 #5
On Aug 9, 10:01 pm, Jo Deni <joachim_denin...@web.dewrote:
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.

Aug 10 '07 #6
and here is the offending line in my code
>
double X = 10000000000;

So what can I do to fix the problem?
double X = 10000000000LL;

Aug 10 '07 #7
On Aug 11, 3:52 am, 440...@email.com wrote:
and here is the offending line in my code
double X = 10000000000;
So what can I do to fix the problem?

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 .

Aug 12 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Thakur | last post by:
I am writing vbscript code in an .asp page. I need to display field values from a sql table consisting of several fields, one of them is of type "Long Text". This field contains XML data. I like to...
1
by: Num | last post by:
Hi all, I have to convert a J2EE date as a long ("Millis") in a .NET date as a long ("Ticks") In Java, currentTimeMillis, is the difference, measured in milliseconds, between the current time...
17
by: Adam Ierymenko | last post by:
I have a question that might have been asked before, but I have not been able to find anything via groups.google.com or any web search that is definative. I am writing an evolutionary AI...
22
by: bq | last post by:
Hello, Two questions related to floating point support: What C compilers for the wintel (MS Windows + x86) platform are C99 compliant as far as <math.h> and <tgmath.h> are concerned? What...
22
by: Vijay | last post by:
With the option strict On set..... Dim fs As FileStream = File.OpenRead(strFile) With fs Dim buffer(fs.Length) As Byte ' <--- Option Strict On disallows implicit conversions from 'Long' to...
12
by: Zero | last post by:
Hi everybody, i want to write a small program, which shows me the biggest and smallest number in dependance of the data type. For int the command could be: ...
28
by: silvia.fama | last post by:
Hi! I'm using c language. I need to copy a long type value into a char string using a memcpy function: memcpy(string, (long *) value, len) this value will be then insert into a database. On...
3
by: ext | last post by:
"A "long" in C is an "int" in C#." Does this mean that whenever passing a parameter to a C function which expects a long type, the variable on C# side should be declared as int type? What if...
3
by: nineoo | last post by:
To all, Ok , now this may sound a little crazy, but does any one know if there is a way to increase the maximum value of a unsigned long int? I'm aware of the the max value of an...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.