• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

How big can an int, long int, float, and double be?

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.
Not sure about the doubles and floats, I thought that the doubles could have a larger value than the float.
 
Doubles are larger than floats. You want signed or unsigned? Cos that makes a huge difference.
 
All the data types could be any size, it just depends on the compiler and architecture.
 
XWRed1 said:
All the data types could be any size, it just depends on the compiler and architecture.

Actually, the integer types cannot be ANY size. The C++ standard requires a char to be at least 8 bits, a short to be at least 16 bits, a long to be at least 32 bits, and an int must be greater than or equal to a short and less then or equal to a long.

If you are programming for the Intel platform, there are typical sizes for the basic data types. Visual C++ .Net is as follows:
max short = 2^15 - 1 = 32767
max unsigned short = 2^16 - 1 = 65535
max int = 2^31 - 1 = 2147483647
max unsigned int = 2^32 - 1 = 4294967295
longs are the same size as ints

I am not aware if the C++ standard requires any particular size for floats, but IEEE specifies a bit format for single and double precision numbers. Visual C++ follows this standard so that floats are 32 bits and doubles are 64 bits. The max values are approximately:
max float = 2^(2^7) = 3.4 x 10^38
max double = 2^(2^10) = 1.798 x 10^308

C++ also has a long double, but that's the same as a double in Visual C++. Intel math coprecessors also support 80 bit floats. I believe the mantissa for those would be 15 bits so max long double is about 2^(2^14) = 1.19 x 10^4932.

Hope this helps.
 
short to be at least 16 bits, a long to be at least 32 bits, and an int must be greater than or equal to a short and less then or equal to a long.

So they COULD be any size as long as they were larger than those minimums. There is no specified max in the language standards, I guess?

You could always be evil and write a crude compiler with insane data type sizes just to screw up this thread.
 
Not to mention that you are going to be in trouble if you are relying on a data type to be larger than the minimum specified. I would not want my program to break just because I used signed integers larger than 32,767, and tried to compile on a non-microsoft compiler. MS has been known to deviate from standards from time to time...
 
srimmer said:
Not to mention that you are going to be in trouble if you are relying on a data type to be larger than the minimum specified. I would not want my program to break just because I used signed integers larger than 32,767, and tried to compile on a non-microsoft compiler. MS has been known to deviate from standards from time to time...

Well, as I said, those sizes listed were fairly typical for compilers for Intel CPU's.

You do make a good point, though. If you MUST have a 32 bit int, you should use a typedef, so that the type can be easily changed.
 
int minimal range is -32,767 to 32,767. long int minimal range is -2,147,483,647 to 2,147,483,647. float minimal range is 1E-37 to 1E+37, with six digits of precision. double minimal range is 1E-37 to 1E+37, with ten digits of precision. But I couldn't understand "An int and long int can have the same range, but an int cannot be larger than a long int."
 
I am assuming C++. Java has specified size.
Now, OP, I am hoping this isn't a homework question. If it is then you should really be googling for this. This is the best site I've found to be:

http://www.cplusplus.com/reference/

Look under limits.h

Edit: just because you have a sexy avatar: the answer to each of these is "system dependent". The greatest value of each of these can be even up to infinity if a compiler is made with bigint support for default types.
 
Last edited:
I am assuming C++. Java has specified size.
Now, OP, I am hoping this isn't a homework question. If it is then you should really be googling for this. This is the best site I've found to be:

If this is a homework question, it's about 6 years too late... :eek:
 
Back