【发布时间】:2013-08-13 08:36:39
【问题描述】:
我正在编写一个程序,它将 CIL 字节码转换为 C 源代码以供机器使用。由于与十进制之间的转换,我担心浮点常量的不准确性。经过一番研究,我发现 C(但不是 C++)应该能够接受浮点常量的十六进制表示法。
我决定尝试一下,但无论我尝试什么,MS VC9 都会给我错误。这是我正在尝试的:
// Switches: /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /FD /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TC
#include <tchar.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
double d = 0x1.0p+1; // error C2059
//double d = 0x1p+1; // doesn't work either
//double d = 0x1p1; // doesn't work either
//double d = 0x1.0p1; // doesn't work either
printf( "%f\n", d );
return 0;
}
我希望这会从 1x2^1 打印出 2,但它却给了我这个编译器错误:
error C2059: syntax error : 'bad suffix on number'
我意识到 C++ 不支持这种语法(或者我已经阅读过),但请注意这是用 /TC 编译的,所以它应该是直接的 C,而且我也使用了 *.c 文件名。
我在这里做错了什么,还是 VC9 不符合标准?
【问题讨论】:
标签: c visual-studio visual-studio-2008 floating-point floating-accuracy