DBL_MAX的类型 [英] Type of DBL_MAX
问题描述
我在某处看到了这段代码
I saw this code somewhere
printf("DBL_MAX : %g\n", (double) DBL_MAX);
演员阵容是否必要?我找不到标准中指定DBL_MAX
实际上必须具有(或提升为)double
类型的任何内容.
Is the cast necessary? I cannot find anything in the standard which specifies DBL_MAX
must actually have (or promote to) type double
.
推荐答案
DBL_MAX
被指定为宏,因此它本身没有类型.
DBL_MAX
is specified to be a macro, so in itself, does not have a type.
1999 C标准的要求是DBL_MAX
必须扩展为至少为1E+37
的恒定值,但是没有提及其实际类型.由于它表示double
可以表示的实现定义的最大值,因此逻辑将建议扩展是可以直接转换为double
的值,而无需进行任何更改(例如,精度损失).
The requirement from the 1999 C standard is that DBL_MAX
must expand to a constant value that is at least 1E+37
, but nothing is said about its actual type. Since it represents the implementation-defined maximum value that a double
can represent, logic would suggest the expansion is a value that can be converted to a double
without any change (e.g. loss of precision).
此逻辑将允许但不要求DBL_MAX
的类型为double
.它也可以是long double
类型(因为还要求long double
能够准确表示double
可以的所有值).
This logic would allow but not require DBL_MAX
to be of type double
. It could also be of type long double
(since it is also required that a long double
can exactly represent all values that a double
can).
实际上,很难设想将DBL_MAX
扩展为非double
类型的常量的实现,而且我当然从没听说过一个实现.但这并不意味着它是必需的. printf("DBL_MAX : %g\n", (double) DBL_MAX)
提供一种保守的保证(就可能发生的可能性而言,即为可能的可能性进行了规定),保证将类型double
的值传递给printf()
.
Practically, it is difficult to envisage an implementation which has DBL_MAX
expand to a constant that is not of type double
, and I certainly have never heard mention of one. But that does not mean it is required. printf("DBL_MAX : %g\n", (double) DBL_MAX)
provides a conservative (in the sense of making provision for a possibility that is allowed, even if it might not occur) guarantee that a value of type double
is passed to printf()
.
这篇关于DBL_MAX的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!