大量浮点数,无需额外库
我有一个数百位长的浮点值(如 pi - 3 的前 100 位),需要一种对其进行操作的方法。有没有什么方法可以存储和操作具有大量小数的浮点数,并通过内置库保持很高的精度? c++中有没有类似python的Decimal模块的东西?
i have a float value that is hundreds of digits long (like the first 100 digits of pi - 3) and need a way to operate on it. is there any way to store and operate on the float that has a large number of decimals and maintain much precision with built in libraries? is there anything like python's Decimal module in c++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
其他答案都指向高精度整数库。然而,有一些浮点库:
...并且不要忘记您始终可以实施自己的解决方案。 (可能不是最有效或最快的解决方案,但如果您想学习一些东西,它是“最佳”解决方案。
The other answers all point to high precision integer libraries. There are however a few floating point libraries around:
... and don't forget the possibility that you can always implement your own solution. (Might not be the most effective or fastest solution, but it's "the" solution if you want to learn something.
没有内置库,但您可以使用 Bignum 算术来做到这一点:) http://en。 wikipedia.org/wiki/Arbitrary- precision_arithmetic。
Bignum 是什么:数字数组(向量)。您可以轻松实现和/差......
我实际上在这里问了类似的问题: STL big int类实现
No built-in library, but you can do that using Bignum arithmetics :) http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic.
What a Bignum is: an array (vector) of digits. You can easily implement sum/difference....
I've actually asked something simillar here: STL big int class implementation
除非它是一些额外的奇特平台,其中浮点长度超过 100 个字节,否则您会发现如果没有大数字库就很难归档您想要的内容。
Unless it is some extra exotic platform, where a float is 100+ bytes long, you will find it hard to archive what you want without a library for big numbers.