有一个C ++等价于Java的BigDecimal? [英] Is there a C++ equivalent to Java's BigDecimal?
问题描述
我在寻找一个可以做十进制浮点运算的C ++类。通过 http://speleotrove.com/decimal/ 可以看到人们已经写入和未维护的各种类的链接。挖掘decNumber ++的东西导致我一些电子邮件显示GCC将最终支持此功能。 (正式名为ISO / IEC TR 24733)
I'm looking for a C++ class that can do decimal floating point arithmetic. Looking through http://speleotrove.com/decimal/ there are links to all sorts of classes that people have written and not maintained. Digging through the decNumber++ stuff led me to some emails showing that GCC will eventually support this functionality. (Formally known as ISO/IEC TR 24733)
我正在寻找一些我可以用来替代float或double的东西,在自己的项目中使用。希望开源。
I'm looking for something I can use as a drop-in replacement for float or double, something that other people are using in their own projects. Hopefully open source.
谢谢!
编辑:我应该指出,代表价格。因此我需要EXACT小数,而不是巨大的小数。
I should point out that I'm trying to use this to represent prices. So I need EXACT decimals, not HUGE decimals.
推荐答案
存在一个名为 GMP(GNU多精度库),它支持这一点,并且也有C ++绑定,但是说实话,C ++接口是有点bit懒和过时。
There exists a huge library called GMP (GNU multiple precision library) which supports this and also has C++ bindings, though to be honest the C++ interface is a bit wonky and outdated.
在文档中的一个例子中,下面创建了一个至少有500位精度的 f
浮点:
An example from the documentation, the following creates a float called f
with at least 500 bits of precision:
mpf_class f(1.5, 500);
这篇关于有一个C ++等价于Java的BigDecimal?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!