如何得到 DOUBLE_MAX?

AFAIK,C 只支持几种数据类型:

int, float, double, char, void enum.

我需要存储一个高达10位数的数字。因为我得到了一个低10位数

INT _ MAX

,我想我需要一个双。

<limits.h>没有 DOUBLE_MAX。我在网上找到了一个 DBL_MAX,上面说这是 LEGACY,而且看起来像是 C + + 。我需要的是双倍吗?为什么没有 DOUBLE_MAX

247869 次浏览

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 are looking for the float.h header.

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

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.

Its in the standard float.h include file. You want DBL_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.