AFAIK, C supports just a few data types:
int, float, double, char, void enum.
I need to store a number that could reach into the high 10 digits. Since I'm getting a low 10 digit # from
INT_MAX
, I suppose I need a double.
<limits.h>
doesn't have a DOUBLE_MAX. I found a DBL_MAX
on the internet that said this is LEGACY and also appears to be C++. Is double what I need? Why is there no DOUBLE_MAX?
Using double
to store large integers is dubious; the largest integer that can be stored reliably in double
is much smaller than DBL_MAX
. You should use long long
, and if that's not enough, you need your own arbitrary-precision code or an existing library.
INT_MAX
is just a definition in limits.h. You don't make it clear whether you need to store an integer or floating point value. If integer, and using a 64-bit compiler, use a LONG
(LLONG
for 32-bit).
Its in the standard float.h include file. You want DBL_MAX
You are looking for the float.h
header.
You get the integer limits in <limits.h>
or <climits>
. Floating point characteristics are defined in <float.h>
for C. In C++, the preferred version is usually std::numeric_limits<double>::max()
(for which you #include <limits>
).
As to your original question, if you want a larger integer type than long
, you should probably consider long long
. This isn't officially included in C++98 or C++03, but is part of C99 and C++11, so all reasonably current compilers support it.
Source: Stackoverflow.com