How do I get DOUBLE_MAX?

CDouble

C Problem Overview


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?

C Solutions


Solution 1 - C

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)

Solution 2 - C

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.

Solution 3 - C

Its in the standard float.h include file. You want DBL_MAX

Solution 4 - C

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.

Solution 5 - C

You are looking for the float.h header.

Solution 6 - C

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).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionP.Brian.MackeyView Question on Stackoverflow
Solution 1 - CRandom832View Answer on Stackoverflow
Solution 2 - CJerry CoffinView Answer on Stackoverflow
Solution 3 - CSodvedView Answer on Stackoverflow
Solution 4 - CR.. GitHub STOP HELPING ICEView Answer on Stackoverflow
Solution 5 - CFemarefView Answer on Stackoverflow
Solution 6 - CentropoView Answer on Stackoverflow