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.
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:
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.)
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 ...
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 ...
发布评论
评论(4)
是的。
float.h
包含常量,例如:FLT_EPSILON、DBL_EPSILON、LDBL_EPSILON
这是可用float
表示的最小非零值,double
和long double
表示形式。FLT_MAX
和FLT_MIN
表示float
可以表示的极端正数和负数。类似的DBL_
和LDBL_
也可用。FLT_DIG、DBL_DIG、LDBL_DIG
定义为十进制位数精度。您要求提供
xxx_MIN
或xxx_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 byfloat
,double
, andlong double
representations.FLT_MAX
andFLT_MIN
represent the extreme positive and negative numbers which can be represented forfloat
. SimilarDBL_
andLDBL_
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 thexxx_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.
float.h
包含许多描述浮点类型各种属性的宏(包括FLT_MIN
和DBL_MIN
)。标准中给出了
float.h
中限制要求的描述(C90 或 C99 - 5.2.4.2.2“浮点类型的特性”)。特别是,根据标准,任何实现都必须支持
float
或double
的下限至少为1E-37
。但实现可以做得比这更好(并在FLT_MIN
和DBL_MIN
中指出它的作用)。如果需要,请参阅此问题,了解如何获取标准文档副本的信息:
float.h
contains many macros describing various properties of the floating types (includingFLT_MIN
andDBL_MIN
).The description of the requirements of the limits in
float.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
forfloat
ordouble
. But an implementation is free to do better than that (and indicate what it does inFLT_MIN
andDBL_MIN
).See this question for information on where to get a copy of the standards documents if you need one:
这里有用的参考是每个计算机科学家应该了解浮点知识算术。
浮点数的本质——它的大小、精度、限制——实际上是由硬件定义的,而不是由编程语言定义的。 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.)
标准草案 (n1401.pdf) 摘录
Wikipedia 有 一篇关于 IEC 559(或更确切地说 IEEE 754)的文章-1985)你可能会觉得有趣。
Excerpts from the Standard draft (n1401.pdf)
Wikipedia has an article about IEC 559 (or rather IEEE 754-1985) you might find interesting.