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

Discussion in 'C++' started by Jo Deni, Aug 10, 2007.

  1. Jo Deni

    Jo Deni Guest

    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
     
    Jo Deni, Aug 10, 2007
    #1
    1. Advertising

  2. Jo Deni

    soxmax Guest

    On Aug 9, 9:01 pm, 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


    try "long long" or "__int64" or "long double" instead of "double"
     
    soxmax, Aug 10, 2007
    #2
    1. Advertising

  3. Jo Deni

    Just me Guest

    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.
     
    Just me, Aug 10, 2007
    #3
  4. Jo Deni

    Kai-Uwe Bux Guest

    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
     
    Kai-Uwe Bux, Aug 10, 2007
    #4
  5. Jo Deni

    Guest

    On Aug 10, 12:01 pm, Jo Deni <> 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
     
    , Aug 10, 2007
    #5
  6. Jo Deni

    Steve Guest

    On Aug 9, 10:01 pm, 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


    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.
     
    Steve, Aug 10, 2007
    #6
  7. Jo Deni

    Guest

    > 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, 2007
    #7
  8. Jo Deni

    Old Wolf Guest

    On Aug 11, 3:52 am, 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 .
     
    Old Wolf, Aug 13, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. music4
    Replies:
    3
    Views:
    914
    CBFalconer
    Jan 5, 2004
  2. Replies:
    0
    Views:
    591
  3. Sebastian Faust

    warning: use of C99 long long integer constant

    Sebastian Faust, Apr 1, 2008, in forum: C Programming
    Replies:
    23
    Views:
    3,189
    Philip Potter
    Apr 2, 2008
  4. Suresh V
    Replies:
    5
    Views:
    3,731
    SaticCaster
    Jul 5, 2010
  5. shin82

    problem with constant too too large

    shin82, Oct 31, 2012, in forum: C Programming
    Replies:
    0
    Views:
    363
    shin82
    Oct 31, 2012
Loading...

Share This Page