max int value?

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

Join Date: Feb 2005
Posts: 3
Reputation: jamboadams is an unknown quantity at this point 
Solved Threads: 0
jamboadams jamboadams is offline Offline
Newbie Poster

max int value?

 
0
  #1
Feb 20th, 2005
hey anyone know what the largest value that can be stored in an integer variable is? likewise is there a double / long type of deal that isnt of float type? thanks
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 45
Reputation: Siersan is an unknown quantity at this point 
Solved Threads: 2
Siersan's Avatar
Siersan Siersan is offline Offline
Speaker of Truth

Re: max int value?

 
0
  #2
Feb 20th, 2005
hey anyone know what the largest value that can be stored in an integer variable is?
That is up to your implementation, but you can assume that the size of an int is the natural word size of your system. A 32 bit system will most likely have 32 bit integers, so the largest value is 4,294,967,296. You can only assume the range of -32,767 to 32,767 for int if you want your code to be portable though. If you want at least a 32 bit data type then long int is the way to go.
likewise is there a double / long type of deal that isnt of float type?
I don't understand what you are asking.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 199
Reputation: Tight_Coder_Ex is an unknown quantity at this point 
Solved Threads: 14
Tight_Coder_Ex's Avatar
Tight_Coder_Ex Tight_Coder_Ex is offline Offline
Junior Poster

Re: max int value?

 
0
  #3
Feb 20th, 2005
There is a file called LIMITS.H that has all the values you are looking for.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 3
Reputation: jamboadams is an unknown quantity at this point 
Solved Threads: 0
jamboadams jamboadams is offline Offline
Newbie Poster

Re: max int value?

 
0
  #4
Feb 20th, 2005
well if you have a float value that is too large for a normal float you can us a double to give it twice the normal memory usage...

i was wondering if there was an int type of variable to do the same.

i am basically working with addition of two hexadecimal numbers each of which can be up to 20 characters long, when i add two of these i am storing it in an int variable, and i am thinking the reason i am having problems with the output is becuase the answer it returns is too large to be stored in the int...
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 45
Reputation: Siersan is an unknown quantity at this point 
Solved Threads: 2
Siersan's Avatar
Siersan Siersan is offline Offline
Speaker of Truth

Re: max int value?

 
0
  #5
Feb 20th, 2005
A 20 character long hexadecimal value would exceed any of C++'s types. Try an arbitrary precision library such as GMP.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 3
Reputation: jamboadams is an unknown quantity at this point 
Solved Threads: 0
jamboadams jamboadams is offline Offline
Newbie Poster

Re: max int value?

 
0
  #6
Feb 20th, 2005
well the project is for a intro level c++ class , so it seems like the prof wouldnt require us to do soemthin that required libraries other than the ones in code warrior to start with. im thinkin im gonna have to store the value as a character array and only convert it to actual numbers when i need to manipulate them, that way i dont have to deal w/ the whole thing as one huge number, jus go one slot at a time thru the array. thanks alot for speedy replies by the way
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: max int value?

 
0
  #7
Feb 20th, 2005
Originally Posted by jamboadams
hey anyone know what the largest value that can be stored in an integer variable is? likewise is there a double / long type of deal that isnt of float type? thanks
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. int main(void)
  5. {
  6. std::cout << std::numeric_limits<int>::max() << std::endl;
  7. std::cout << std::numeric_limits<double>::max() << std::endl;
  8. return 0 ;
  9. }
  10.  
  11. /* my output
  12. 2147483647
  13. 1.79769e+308
  14. */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 199
Reputation: Tight_Coder_Ex is an unknown quantity at this point 
Solved Threads: 14
Tight_Coder_Ex's Avatar
Tight_Coder_Ex Tight_Coder_Ex is offline Offline
Junior Poster

Re: max int value?

 
0
  #8
Feb 21st, 2005
Originally Posted by jamboadams
im thinkin im gonna have to store the value as a character array and only convert it to actual numbers when i need to manipulate them
Exactly. I've never found the need to do something like this with binary numbers, but before co-processors I coded this kind of thing on the Z80 to give me 128 digit precision in BCD (Binary Coded Decimals).
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 10
Reputation: 35nando is an unknown quantity at this point 
Solved Threads: 0
35nando 35nando is offline Offline
Newbie Poster

Re: max int value?

 
0
  #9
Feb 25th, 2009
Originally Posted by Siersan View Post
the largest value is 4,294,967,296.
The largest int ist 2^31 = 2147483647.
One bit is used to store the sign.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,675
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: max int value?

 
0
  #10
Feb 25th, 2009
Originally Posted by jamboadams View Post
well the project is for a intro level c++ class , so it seems like the prof wouldnt require us to do soemthin that required libraries other than the ones in code warrior to start with. im thinkin im gonna have to store the value as a character array and only convert it to actual numbers when i need to manipulate them, that way i dont have to deal w/ the whole thing as one huge number, jus go one slot at a time thru the array. thanks alot for speedy replies by the way
Yep, that's why we make assignments like that.
"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  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC