1,105,344 Community Members

max int value?

Member Avatar
jamboadams
Newbie Poster
3 posts since Feb 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Siersan
Light Poster
45 posts since Jan 2005
Reputation Points: 1 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
Tight_Coder_Ex
Posting Whiz in Training
215 posts since Feb 2005
Reputation Points: 17 [?]
Q&As Helped to Solve: 17 [?]
Skill Endorsements: 0 [?]
 
0
 

There is a file called LIMITS.H that has all the values you are looking for.

Member Avatar
jamboadams
Newbie Poster
3 posts since Feb 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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...

Member Avatar
Siersan
Light Poster
45 posts since Jan 2005
Reputation Points: 1 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

A 20 character long hexadecimal value would exceed any of C++'s types. Try an arbitrary precision library such as GMP.

Member Avatar
jamboadams
Newbie Poster
3 posts since Feb 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Dave Sinkula
long time no c
4,852 posts since Apr 2004
Reputation Points: 2,398 [?]
Q&As Helped to Solve: 340 [?]
Skill Endorsements: 69 [?]
Team Colleague
 
0
 

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

#include <iostream>
#include <limits>

int main(void)
{
   std::cout << std::numeric_limits<int>::max()    << std::endl;
   std::cout << std::numeric_limits<double>::max() << std::endl;
   return 0 ;
}

/* my output
2147483647
1.79769e+308
*/
Member Avatar
Tight_Coder_Ex
Posting Whiz in Training
215 posts since Feb 2005
Reputation Points: 17 [?]
Q&As Helped to Solve: 17 [?]
Skill Endorsements: 0 [?]
 
0
 

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).

Member Avatar
35nando
Newbie Poster
10 posts since Dec 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

the largest value is 4,294,967,296.

The largest int ist 2^31 = 2147483647.
One bit is used to store the sign.

Member Avatar
vmanes
Postaholic
2,140 posts since Aug 2007
Reputation Points: 1,165 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 10 [?]
 
0
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article