浮点的下界

发布于 2024-08-10 07:39:08 字数 43 浏览 6 评论 0 原文

C 中的浮点类型有下限吗?就像整数类型有下限(int 至少 16 位)?

Are there any lower bounds for floating point types in C? Like there are lower bounds for integral types (int being at least 16 bits)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小ぇ时光︴ 2024-08-17 07:39:08

是的。 float.h 包含常量,例如:

FLT_EPSILON、DBL_EPSILON、LDBL_EPSILON 这是可用 float 表示的最小非零值, doublelong double 表示形式。

FLT_MAXFLT_MIN 表示 float 可以表示的极端正数和负数。类似的 DBL_LDBL_ 也可用。

FLT_DIG、DBL_DIG、LDBL_DIG定义为十进制位数精度。

您要求提供 xxx_MINxxx_EPSILON 值。

沿着这些思路,这里有一个问题,其中 我发布了一些显示 64 位 IEEE-754 浮点数内部结构的代码。

Yes. float.h contains constants such as:

FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON this is the least magnitude non-zero value which can be represented by float, double, and long double representations.

FLT_MAX and FLT_MIN represent the extreme positive and negative numbers which can be represented for float. Similar DBL_ and LDBL_ are available.

FLT_DIG, DBL_DIG, LDBL_DIG are defined as the number of decimal digits precision.

You are asking for either the xxx_MIN or the xxx_EPSILON value.

Along these lines, here is a question wherein I posted some code which displays the internals of a 64-bit IEEE-754 floating-point number.

余生再见 2024-08-17 07:39:08

float.h 包含许多描述浮点类型各种属性的宏(包括 FLT_MINDBL_MIN)。

标准中给出了float.h 中限制要求的描述(C90 或 C99 - 5.2.4.2.2“浮点类型的特性”)。

特别是,根据标准,任何实现都必须支持 floatdouble 的下限至少为 1E-37。但实现可以做得比这更好(并在 FLT_MINDBL_MIN 中指出它的作用)。

如果需要,请参阅此问题,了解如何获取标准文档副本的信息:

float.h contains many macros describing various properties of the floating types (including FLT_MIN and DBL_MIN).

The description of the requirements of the limits infloat.h is given in the standard (C90 or C99 - 5.2.4.2.2 "Characteristics of floating types").

In particular, according to the standard any implementation must support a lower-bound of at least 1E-37 for float or double. But an implementation is free to do better than that (and indicate what it does in FLT_MIN and DBL_MIN).

See this question for information on where to get a copy of the standards documents if you need one:

£烟消云散 2024-08-17 07:39:08

这里有用的参考是每个计算机科学家应该了解浮点知识算术

浮点数的本质——它的大小、精度、限制——实际上是由硬件定义的,而不是由编程语言定义的。 x86 上的单精度浮点与 C、C#、Java 和任何其他实用编程语言中的单精度浮点相同。 (例外是在软件中实现奇数宽度浮点数的深奥编程语言。)

A useful reference here is What Every Computer Scientist Should Know About Floating-Point Arithmetic.

The nature of a floating point number — its size, precision, limits — is really defined by the hardware, rather than the programming language. A single-precision float on an x86 is the same in C, C#, Java, and any other practical programming language. (The exception is esoteric programming languages that implement odd widths of floating point number in software.)

笔落惊风雨 2024-08-17 07:39:08

标准草案 (n1401.pdf) 摘录

                                      Annex F
                                    (normative)
                       IEC 60559 floating-point arithmetic
    F.1 Introduction
1   ... An implementation that defines _ _STDC_IEC_559_ _ shall conform to
    the specifications in this annex. ...

    F.2 Types
1   The C floating types match the IEC 60559 formats as follows:
    -- The float type matches the IEC 60559 single format.
    -- The double type matches the IEC 60559 double format.
    -- The long double type matches an IEC 60559 extended format ...

Wikipedia 有 一篇关于 IEC 559(或更确切地说 IEEE 754)的文章-1985)你可能会觉得有趣。

Excerpts from the Standard draft (n1401.pdf)

                                      Annex F
                                    (normative)
                       IEC 60559 floating-point arithmetic
    F.1 Introduction
1   ... An implementation that defines _ _STDC_IEC_559_ _ shall conform to
    the specifications in this annex. ...

    F.2 Types
1   The C floating types match the IEC 60559 formats as follows:
    -- The float type matches the IEC 60559 single format.
    -- The double type matches the IEC 60559 double format.
    -- The long double type matches an IEC 60559 extended format ...

Wikipedia has an article about IEC 559 (or rather IEEE 754-1985) you might find interesting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文