C语言 我如何获得 DOUBLE_MAX?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5834635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 08:32:26  来源:igfitidea点击:

How do I get DOUBLE_MAX?

cdouble

提问by P.Brian.Mackey

AFAIK, C supports just a few data types:

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

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

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

INT_MAX

INT_MAX

, I suppose I need a double.

,我想我需要一个双人。

<limits.h>doesn't have a DOUBLE_MAX. I found a DBL_MAXon the internet that said this is LEGACY and also appears to be C++. Is double what I need? Why is there no DOUBLE_MAX?

<limits.h>没有 DOUBLE_MAX。我DBL_MAX在互联网上发现一个说这是 LEGACY 并且似乎也是 C++。是我需要的两倍吗?为什么没有 DOUBLE_MAX?

回答by Random832

DBL_MAXis defined in <float.h>. Its availability in <limits.h>on unix is what is marked as "(LEGACY)".

DBL_MAX中定义<float.h>。它在<limits.h>unix 上的可用性被标记为“(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)

(即使您没有 unix 标签,也链接到 unix 标准,因为这可能是您找到“LEGACY”符号的地方,但是 float.h 中显示的大部分内容也在 C 标准中回到 C89)

回答by Jerry Coffin

You get the integerlimits 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>).

您在or 中获得整数限制。浮点特性在for C中定义。在 C++ 中,首选版本通常是(for which you )。<limits.h><climits><float.h>std::numeric_limits<double>::max()#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.

至于你原来的问题,如果你想要一个比 更大的整数类型long,你可能应该考虑long long. 这并未正式包含在 C++98 或 C++03 中,而是 C99 和 C++11 的一部分,因此所有合理的当前编译器都支持它。

回答by Sodved

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

它在标准的 float.h 包含文件中。你要DBL_MAX

回答by R.. GitHub STOP HELPING ICE

Using doubleto store large integers is dubious; the largest integer that can be stored reliably in doubleis 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.

使用double存储大整数是可疑的; 可以可靠存储的最大整数double远小于DBL_MAX. 您应该使用long long,如果这还不够,您需要自己的任意精度代码或现有库。

回答by entropo

INT_MAXis 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(LLONGfor 32-bit).

INT_MAX只是limits.h 中的一个定义。您没有明确是需要存储整数还是浮点值。如果是整数,并且使用 64 位编译器,则使用LONG(LLONG表示 32 位)。

回答by Femaref

You are looking for the float.hheader.

您正在寻找float.h标题。