How do I get DOUBLE_MAX?

前端 未结 6 2198
我在风中等你
我在风中等你 2020-12-14 05:24

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 di

相关标签:
6条回答
  • 2020-12-14 05:52

    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.

    0 讨论(0)
  • 2020-12-14 05:57

    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)

    0 讨论(0)
  • 2020-12-14 05:59

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

    0 讨论(0)
  • 2020-12-14 06:02

    You are looking for the float.h header.

    0 讨论(0)
  • 2020-12-14 06:10

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

    0 讨论(0)
  • 2020-12-14 06:15

    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.

    0 讨论(0)
提交回复
热议问题