How to define a long long integer in C++ (I use Linux, 32 bit)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 4
Reputation: arunciblesp00n is an unknown quantity at this point 
Solved Threads: 0
arunciblesp00n arunciblesp00n is offline Offline
Newbie Poster

How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #1
Dec 18th, 2008
Hello,

Firstly I better warn you I'm quite new to C++ and to Linux so I'm sorry if my terminology/general understanding of how things work is a bit confused.

I've downloaded a code which is in C which is helpful for a course I'm doing on stellar structure, but I'd like to use it with C++. Everything translates just fine apart from the the definition of the maximum of a number as a "long long int". Apparently C++ doesn't support this form.

I use Linux (32 bit) and I'd like to be able to use that integer in my programme. Is there a library or particular compiler I can use so that I can have numbers like that in the programme, or is there a solution I can find without downloading anything? I currently use g++. My first thought was to turn the number into a double, as that stopped the errors appearing, but after a conversation with a more computer-literate friend, I've realised how ineffective that was (just to give you an idea of my level of understanding of these things).

If there's something I need to download, please could you send me a link, and ideally give me a bit of instruction as to exactly what I need to do with it once I've downloaded it, and what I'd need to include in the programme to use it (as I said, I'm very inexperienced with both the operating system and the programming language!)

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #2
Dec 18th, 2008
I thought most modern c and c++ compilers supported some form of 64-bit integers. Try just "long long" instead of "long long int".
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: arunciblesp00n is an unknown quantity at this point 
Solved Threads: 0
arunciblesp00n arunciblesp00n is offline Offline
Newbie Poster

Re: How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #3
Dec 18th, 2008
Thanks for the reply. I've tried that, and it doesn't seem to help. I just get the error "integer constant is too large for "long" type.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #4
Dec 18th, 2008
Please post your program -- maybe there is something else wrong with it. I don't have a *nix os so I can't really help you much.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: arunciblesp00n is an unknown quantity at this point 
Solved Threads: 0
arunciblesp00n arunciblesp00n is offline Offline
Newbie Poster

Re: How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #5
Dec 18th, 2008
  1. //The smallest non-zero number and the number of significant figures
  2.  
  3. const float tiny_sp = 3.4e-38F;
  4.  
  5. const double tiny_dp = 1.7e-308;
  6.  
  7. const long double tiny_qp = tiny_dp;
  8.  
  9. const short int sig_fig_sp = 7;
  10.  
  11. const short int sig_fig_dp = 15;
  12.  
  13. const short int sig_fig_qp = sig_fig_dp;
  14.  
  15. const float eps_sp = 1E-6;
  16.  
  17. const double eps_dp = 1E-15;
  18.  
  19. const long double eps_qp = eps_dp;
  20.  
  21.  
  22.  
  23. //The largest number for given precision
  24.  
  25. const float biggest_sp = 3.4e38F;
  26.  
  27. const double biggest_dp = 1.7e308;
  28.  
  29. const long double biggest_qp = biggest_dp;
  30.  
  31. const short int biggest_i2 = 32767;
  32.  
  33. const long int biggest_i4 = 2147483647;
  34.  
  35. const long long int biggest_i8 = 9223372036854775807;

That's the top part of the code I'm using for defining. I link several other C++ codes together to form the overall programme, but when I try to do that the errors which come up are all related to the constant defined in the bottom line of this.
Last edited by Ancient Dragon; Dec 18th, 2008 at 10:16 pm. Reason: correct code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,674
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #6
Dec 19th, 2008
That value is correct as maximum for signed long long.

What specific compiler are you using?

Look at the include file <limits.h> to see what types and their ranges are available in that compiler.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,674
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #7
Dec 19th, 2008
Try putting "LL" after the literal value, as in:
const long long int biggest_i8 = 9223372036854775807LL;
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #8
Dec 19th, 2008
Alas, long long int is not a standard type in C++ at the moment. Moreover, the C++ (and C) standard garantees that long number type is not less that ordinar type - that's all (for example, sizeof(long long int) >= sizeof(long int) , but not sizeof(long long) > sizeof(long) ).

Therefore it was a very careless project decision to rely upon non-standard long long int POD type with huge values range.

There are arbitrary precision integer arithmetics libraries for C++ and C but it seems you need too serious code refactoring to use those libraries (it's easier to move to double type).

If it's a very long (long long ) code use Windows+VC++ compiler with 64-bit long long type extension. Regrettably I don't know proper linux compilers with 64-bit long long (ask linux guru)...
Last edited by ArkM; Dec 19th, 2008 at 4:29 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: arunciblesp00n is an unknown quantity at this point 
Solved Threads: 0
arunciblesp00n arunciblesp00n is offline Offline
Newbie Poster

Re: How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #9
Dec 19th, 2008
Thanks for the information.

Could anyone suggest a Linux compiler with a 64-bit long long type extension? I've been having a look and can't seem to find anything. If anyone has any further ideas for how to fix this please let me know.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to define a long long integer in C++ (I use Linux, 32 bit)

 
0
  #10
Dec 19th, 2008
Doesn't the latest version of g++ support it? Maybe you just need to download the lastest version. GNU is usually pretty good at keeping those compilers up-to-date.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC