对于此代码,
#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终止所有浮点文字。但无论如何,如果没有它,我不会期待编译错误。
等式在Excel中生成。