PDA

View Full Version : How big can an int, long int, float, and double be?



Octoman
05-18-03, 02:39 PM
What is the greatest positive value of each be?


int:


long int:


float:


double:




Thanks for the help.

ziptieboy
05-18-03, 03:27 PM
Double: 10^308
Int: 32,767
Long: 2,147,483,647
Float: Aren't these the same as Doubles?

Octoman
05-18-03, 03:48 PM
Not sure about the doubles and floats, I thought that the doubles could have a larger value than the float.

flux
05-18-03, 03:53 PM
Doubles are larger than floats. You want signed or unsigned? Cos that makes a huge difference.

XWRed1
05-18-03, 04:57 PM
All the data types could be any size, it just depends on the compiler and architecture.

jrl
05-20-03, 12:45 AM
Originally posted by XWRed1
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.

XWRed1
05-20-03, 05:39 AM
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.

Cowboy Shane
05-20-03, 07:26 AM
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...

jrl
05-20-03, 10:24 AM
Originally posted by srimmer
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.

BobSue
05-08-09, 10:53 AM
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."

ShadowPho
05-10-09, 03:53 PM
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.

Trombe
05-10-09, 04:11 PM
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:

ShadowPho
05-10-09, 08:28 PM
If this is a homework question, it's about 6 years too late... :eek:

This is what I get for visiting this forum once every two weeks :D
I don't notice threads which have been ressurected once in 6 years!