Question:
What is the largest value a float, double and int can hold in C?
Detective Conan
2009-07-31 13:35:02 UTC
What is the largest value a float, double and int can hold in C?

Please give in both number and exponent form.
Four answers:
Mark aka jack573
2009-08-03 15:32:02 UTC
As the other answerer said, it depends on your compiler, environment, etc.



You can find this out for yourself by looking at the folder where your compiler is. It should have an include folder with it. Look inside this folder for a limits.h file.



Have a look in this file. One of my limits.h files directs me to the _lim.h file. Inside the _lim.h file there is this (among ther things).



#define CHAR_BIT 8 /* number of bits in a char */

#define MB_LEN_MAX 2 /* max. # bytes in multibyte char */



#define SCHAR_MIN (-128) /* minimum signed char value */

#define SCHAR_MAX 127 /* maximum signed char value */

#define UCHAR_MAX 255 /* maximum unsigned char value */



#if ('\x80' < 0)

#define CHAR_MIN SCHAR_MIN /* minimum char value */

#define CHAR_MAX SCHAR_MAX /* maximum char value */

#else

#define CHAR_MIN 0

#define CHAR_MAX UCHAR_MAX

#endif



#define SHRT_MIN (-32767-1) /* minimum signed short value */

#define SHRT_MAX 32767 /* maximum signed short value */

#define USHRT_MAX 65535U /* maximum unsigned short value */



#define LONG_MIN (-2147483647L-1) /* minimum signed long value */

#define LONG_MAX 2147483647L /* maximum signed long value */

#define ULONG_MAX 4294967295UL /* maximum unsigned long value */



#if defined (_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS >= 64)

#define _I64_MIN (-9223372036854775807i64-1) /* minimum signed __int64 value */

#define _I64_MAX 9223372036854775807i64 /* maximum signed __int64 value */

#define _UI64_MAX 18446744073709551615ui64 /* maximum unsigned __int64 value */

#endif



#define INT_MIN LONG_MIN /* minimum signed int value */

#define INT_MAX LONG_MAX /* maximum signed int value */

#define UINT_MAX ULONG_MAX /* maximum unsigned int value */





Also check the float.h file. The float.h has:



#define FLT_RADIX 2

#define FLT_ROUNDS 1

#define FLT_GUARD 1

#define FLT_NORMALIZE 1



#define DBL_DIG 15

#define FLT_DIG 6

#define LDBL_DIG 18



#define DBL_MANT_DIG 53

#define FLT_MANT_DIG 24

#define LDBL_MANT_DIG 64



#define DBL_EPSILON 2.2204460492503131E-16

#define FLT_EPSILON 1.19209290E-07F

#define LDBL_EPSILON 1.084202172485504434e-019L



/* smallest positive IEEE normal numbers */

#define DBL_MIN 2.2250738585072014E-308

#define FLT_MIN 1.17549435E-38F

#define LDBL_MIN _tiny_ldble



#define DBL_MAX _max_dble

#define FLT_MAX _max_flt

#define LDBL_MAX _max_ldble



#define DBL_MAX_EXP +1024

#define FLT_MAX_EXP +128

#define LDBL_MAX_EXP +16384



#define DBL_MAX_10_EXP +308

#define FLT_MAX_10_EXP +38

#define LDBL_MAX_10_EXP +4932



#define DBL_MIN_10_EXP -307

#define FLT_MIN_10_EXP -37

#define LDBL_MIN_10_EXP -4931



#define DBL_MIN_EXP -1021

#define FLT_MIN_EXP -125

#define LDBL_MIN_EXP -16381



Hope that helps.
2016-11-16 11:03:16 UTC
Max Float Value
2016-03-18 13:52:44 UTC
C and C++ are intentionally very close to the features available on a typical actual binary computer, and the data types you mention simply don't exist on such machines. Outside of cryptography and some other applied number-theory applications, there's not that much demand for fixed point integers that are megabytes in size. (2^n takes a minimum of n bits of storage for fixed-point representation and for n=10 million, that's 1.25 megabytes per number.) There are arbitrary-precision packages available for C and C++, but for experimenting with computation and getting a feel for how long it takes to do arithmetic with such huge numbers, you could try the Python language. The "long" type in Python is as long as it needs to be to store your number--up to the amount of available memory on your computer. Java has had a BigInteger type for over a decade, and C# recently got one with .NET 4.0 (you need to use Visual Studio 2010 to develop for 4.0), if you want something that's more like a compiled language. Neither of these is quite as "built-in" as the long type in Python, though.
adderek
2009-07-31 13:45:30 UTC
ANSI C or C++ or C#?

In C++/C# try float.MAXVALUE.

In ANSI C there is probably something like MAXVALUE(float) (you need to check that).

Never ever rely on the minimum/maximum value of variable not its size.

Examples:

Integer can be 0-255 or -127-128 or -32768-32767 or ... (depending on the environment it might be signed/unsigned, 1-byte, 2-byte, 4-byte, 7-bits, 8-bits, etc.)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...