C语言中的大整数?
在 C 中处理大量数字的最简单方法是什么? 我需要将值存储在区域 1000^900
中,或者以更易于理解的形式 10^2700
存储。
有谁知道一个简单的方法来做到这一点? 任何帮助将不胜感激!
What is the easiest way to handle huge numbers in C? I need to store values in the Area 1000^900
, or in more human readable form 10^2700
.
Does anybody know of an easy way to do that? Any help would really be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有许多库可以处理大量数据。 您需要整数或浮点运算吗?
您可以查看 Python 中内置的用于该任务的代码。
您可以查看 Perl 的扩展来完成该任务。
您可以查看 OpenSSL 中的代码来完成该任务。
您可以查看 GNU MP(多精度)库 - 正如 kmkaplan 所提到的。
There are a number of libraries for handling huge numbers around. Do you need integer or floating point arithmetic?
You could look at the code built into Python for the task.
You could look at the extensions for Perl for the task.
You could look at the code in OpenSSL for the task.
You could look at the GNU MP (multi-precision) library - as mentioned by kmkaplan.
您还可以尝试 openssl 的 BIGNUM,请参阅 https://www. openssl.org/docs/man1.0.2/man3/bn.html,https://www.openssl.org/docs/man1.1.1/man3/,将作为字符串给出的大数字转换为 OpenSSL BIGNUM 了解详细信息。
You can also try the BIGNUMs of openssl, see https://www.openssl.org/docs/man1.0.2/man3/bn.html, https://www.openssl.org/docs/man1.1.1/man3/, Convert a big number given as a string to an OpenSSL BIGNUM for details.
使用 libgmp:
Use libgmp:
有一些库可以帮助您做到这一点(任意精度数学):
其他人。 假设这与工作无关(即,您这样做是为了好玩,或者是一种爱好,或者只是一个学习东西的机会),那么为任意精度数学编写一个库是一个相对有趣的项目。 但是,如果您需要绝对依赖它并且对具体细节不感兴趣,则只需使用库即可。
There are a few libraries to help you do this (arbitrary precision mathematics):
Assuming this isn't work related (ie you're doing it for fun or its a hobby or just an oportunity to learn something), coding up a library for arbitrary precision maths is a relatively interesting project. But if you need to absolutely rely on it and aren't interested in the nuts and bolts just use a library.