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
?
Remarks. The value of this constant is positive 1.7976931348623157E+308.
Double. MAX_VALUE is the maximum value a double can represent (somewhere around 1.7*10^308).
MAX_VALUE. A constant holding the largest positive finite value of type double , (2-2-52)·21023. It is equal to the hexadecimal floating-point literal 0x1.
A signed 32-bit integer variable has a maximum value of 231 − 1 = 2,147,483,647, whereas an IEEE 754 32-bit base-2 floating-point variable has a maximum value of (2 − 2−23) × 2127 ≈ 3.4028235 × 1038.
DBL_MAX
is defined in <float.h>
. Its availability in <limits.h>
on unix is what is marked as "(LEGACY)".
(linking to the unix standard even though you have no unix tag since that's probably where you found the "LEGACY" notation, but much of what is shown there for float.h is also in the C standard back to C89)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With