[英]Setting FLT_EVAL_METHOD not working
#include <stdio.h>
#include <float.h>
#ifdef FLT_EVAL_METHOD
#undef FLT_EVAL_METHOD
#define FLT_EVAL_METHOD 1
#else
#define FLT_EVAL_METHOD 1
#endif
int main(void)
{
printf("%f\n%f\n", FLT_MAX, DBL_MAX);
float fp = FLT_MAX;
printf("%f\n", fp + 1);
printf("%f\n", FLT_MAX + 1);
printf("%f\n", (float) FLT_MAX + 1);
}
The expected output is: 预期的产出是:
340282346638528859811704183484516925440.000000
179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000
340282346638528859811704183484516925441.000000
340282346638528859811704183484516925441.000000
340282346638528859811704183484516925441.000000
But the actual output is: 但实际输出是:
340282346638528859811704183484516925440.000000
179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000
340282346638528859811704183484516925440.000000
340282346638528859811704183484516925440.000000
340282346638528859811704183484516925440.000000
Since FLT_EVAL_METHOD
is set to 1, shouldn't all float
expressions evaluated as double
s? 由于
FLT_EVAL_METHOD
设置为1,所以不应将所有float
表达式计算为double
s吗? What does "evaluate float and double as double, and long double as long double." 什么“评价浮动和加倍为双倍,长加倍为双倍。” mean?
意思? Are
float
s treated identical to double
s? float
处理是否与double
s相同?
FLT_EVAL_METHOD
is not a switch that the programmer uses to control the compiler. FLT_EVAL_METHOD
不是程序员用来控制编译器的开关。 It's a means for the compiler/platform to report to the programmer how floating-point expressions will be evaluated. 它是编译器/平台向程序员报告如何评估浮点表达式的一种手段。 You're not supposed to change its value, and doing so is not supposed to have any effect on anything.
你不应该改变它的价值,这样做不应该对任何事情产生任何影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.