对于这段代码,
#include <math.h>
int main()
{
float x = 1.5f;
float y = 0.0f;
/*line6*/ y = pow(x, 6) * 235809835.41 - pow(x, 5) * 2110439254.2 + pow(x, 4) *7869448124.8 - pow(x, 3) * 15648965509 + pow(x, 2) * 17503313074 - (x)* 10440563329 + 2594694745; // error
/*line7*/ y = pow(x, 6) * 235809835.41 - pow(x, 5) * 2110439254.2 + pow(x, 4) *7869448124.8 - pow(x, 3) * 15648965509 + pow(x, 2) * 17503313074 - (x)* 10440563329 + 2594694745;
return 0;
}
我收到以下错误日志 -
maincpp.cpp(6) : warning C4244 : '=' : conversion from 'double' to 'float', possible loss of data
maincpp.cpp(6) : error C2146 : syntax error : missing ';' before identifier ''
maincpp.cpp(6) : error C2065 : '' : undeclared identifier
第6行无法编译。我发现最令人惊讶的是,第7行即使与第6行相同,也能编译通过。因此,如果我注释掉第6行并保留第7行,则程序可以成功编译。
我使用的是Windows 8 64位系统,这个程序是在Visual Studio 2013中作为Win 32控制台应用程序编写的。
在生产代码中,我会在所有浮点数字面值后加上f。但无论如何,我不期望没有加f就会出现编译错误。
这个方程是在Excel中生成的。