max*_*zig 5 floating-point gcc decimal
GCC文档描述了近期GCC 中有限的十进制浮点支持.
但是我如何实际使用它呢?
例如在Fedora 18,GCC 4.7.2上.
一个简单的C程序就像
int main()
{
_Decimal64 x = 0.10dd;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译(当使用-std = gnu99时) - 但我如何实际做其他有用的东西 - 比如打印_Decimal64值或将字符串转换为_Decimal64值?
文档讨论了(我假设)像printf这样的"单独的C库实现" - 我必须使用哪个额外的库 - 比如说 - 打印十进制浮点计算的结果?
我试过了
printf("%Df\n", x);
Run Code Online (Sandbox Code Playgroud)
哪个不起作用 - printf刚生产:%Df.
正如文档所说,GCC不提供I/O,因为printf等等由libc提供,而不是由GCC提供.
IBM为GNU C库libdfp做了一个扩展,它增加了一些printf钩子来实现Decimal I/O工作.我没有使用它,但你应该能够从eglibc svn存储库获取代码并自己构建它:
svn co http://www.eglibc.org/svn/libdfp/trunk libdfp
Run Code Online (Sandbox Code Playgroud)
网络搜索表明Ubuntu将其打包为libdfp,并且它也可能在RHEL6上可用.
自述文件说:
When libdfp is loaded printf will recognize the following length modifiers:
%H - for _Decimal32
%D - for _Decimal64
%DD - for _Decimal128
It will recognize the following conversion specifier 'spec' characters:
e,E
f,F
g,G
a,A (as debuted in ISO/IEC TR 24732)
Therefore, any combination of DFP length modifiers and spec characters is
supported.
Run Code Online (Sandbox Code Playgroud)