问题描述
limits.h
指定非浮点数学类型的限制,例如INT_MIN
和 INT_MAX
.这些值是您可以使用 int 表示的最负值和最正值.
limits.h
specifies limits for non-floating point math types, e.g. INT_MIN
and INT_MAX
. These values are the most negative and most positive values that you can represent using an int.
在 float.h
中,有 FLT_MIN
和 FLT_MAX
的定义.如果您执行以下操作:
In float.h
, there are definitions for FLT_MIN
and FLT_MAX
. If you do the following:
NSLog(@"%f %f", FLT_MIN, FLT_MAX);
你会得到以下输出:
FLT_MIN = 0.000000, FLT_MAX = 340282346638528859811704183484516925440.000000
FLT_MAX
等于一个非常大的数字,如您所料,但为什么 FLT_MIN
等于零而不是一个非常大的负数?
FLT_MAX
is equal to a really large number, as you would expect, but why does FLT_MIN
equal zero instead of a really large negative number?
推荐答案
它实际上不是零,但如果你使用 printf
或 NSLog
检查它可能看起来像零通过使用 %f
.
根据 float.h
(至少在 Mac OS X 10.6.2 中),FLT_MIN
被描述为:
It's not actually zero, but it might look like zero if you inspect it using printf
or NSLog
by using %f
.
According to float.h
(at least in Mac OS X 10.6.2), FLT_MIN
is described as:
/* Minimum normalized positive floating-point number, b**(emin - 1). */
注意那句话中的正:FLT_MIN
指的是最小(标准化)数大于零.(还有更小的非归一化数字).
Note the positive in that sentence: FLT_MIN
refers to the minimum (normalized) number greater than zero. (There are much smaller non-normalized numbers).
如果你想要最小的浮点数(包括负数),使用-FLT_MAX
.
If you want the minimum floating point number (including negative numbers), use -FLT_MAX
.
这篇关于为什么 FLT_MIN 等于 0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!