| | |
How to define a long long integer in C++ (I use Linux, 32 bit)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 4
Reputation:
Solved Threads: 0
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!
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!
•
•
Join Date: Dec 2008
Posts: 4
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
//The smallest non-zero number and the number of significant figures const float tiny_sp = 3.4e-38F; const double tiny_dp = 1.7e-308; const long double tiny_qp = tiny_dp; const short int sig_fig_sp = 7; const short int sig_fig_dp = 15; const short int sig_fig_qp = sig_fig_dp; const float eps_sp = 1E-6; const double eps_dp = 1E-15; const long double eps_qp = eps_dp; //The largest number for given precision const float biggest_sp = 3.4e38F; const double biggest_dp = 1.7e308; const long double biggest_qp = biggest_dp; const short int biggest_i2 = 32767; const long int biggest_i4 = 2147483647; 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
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.
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.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Try putting "LL" after the literal value, as in:
const long long int biggest_i8 = 9223372036854775807LL;
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.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
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,
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)...
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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Pointer Array to templates
- Next Thread: I need help!
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






