Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++: integer constant is too large for "long" type

Reply
Thread Tools

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

 
 
Jo Deni
Guest
Posts: n/a
 
      08-10-2007
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

 
Reply With Quote
 
 
 
 
soxmax
Guest
Posts: n/a
 
      08-10-2007
On Aug 9, 9:01 pm, Jo Deni <(E-Mail Removed)> 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


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

 
Reply With Quote
 
 
 
 
Just me
Guest
Posts: n/a
 
      08-10-2007
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.
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      08-10-2007
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
 
Reply With Quote
 
tony_in_da_uk@yahoo.co.uk
Guest
Posts: n/a
 
      08-10-2007
On Aug 10, 12:01 pm, Jo Deni <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      08-10-2007
On Aug 9, 10:01 pm, Jo Deni <(E-Mail Removed)> 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


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.

 
Reply With Quote
 
440gtx@email.com
Guest
Posts: n/a
 
      08-10-2007
> and here is the offending line in my code
>
> double X = 10000000000;
>
> So what can I do to fix the problem?


double X = 10000000000LL;

 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      08-12-2007
On Aug 11, 3:52 am, (E-Mail Removed) 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 .

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with constant too too large shin82 C Programming 0 10-31-2012 06:12 PM
decimal constant too large kerravon C Programming 26 11-12-2007 07:44 AM
Web get command (wget) to download all icons/pics on a web page (too large or too small) barb Digital Photography 5 08-04-2006 07:06 PM
Re: Are these pictures too dark or/and too large? Luigi Donatello Asero HTML 0 05-21-2004 09:40 PM
Are these pictures too dark or/and too large? Luigi Donatello Asero HTML 13 05-21-2004 04:54 AM



Advertisments