GMP 任意精度运算

发布于 2024-11-16 10:44:41 字数 71 浏览 6 评论 0原文

我正在使用 GMP 库制作一个 Pi 程序,它将计算大约 7 万亿位的 Pi。问题是,我无法弄清楚需要多少位来保存那么多小数位。

I'm using the GMP library to make a Pi program, that will calculate about 7 trillion digits of Pi. Problem is, I can't figure out how many bits are needed to hold that many decimal places.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赠意 2024-11-23 10:44:41

7 万亿位数字可以表示 10^(7 万亿) 个不同数字中的任何一个。

x 位可以表示 2^x 个不同的数字。

所以你想解决:

2^x = 10^7000000000000

取两边的 log-base-2:

x = log2(10^7000000000000)

回想一下 log(a^b) = b * log(a)

x = 7000000000000 * log2(10)

我得到 <代码>23253496664212位。为了安全起见,我会再添加一两个。不过,祝你好运,找到 PB 来容纳它们。

我怀疑您将需要一个更有趣的算法。

7 trillion digits can represent any of 10^(7 trillion) distinct numbers.

x bits can represent 2^x distinct numbers.

So you want to solve:

2^x = 10^7000000000000

Take the log-base-2 of both sides:

x = log2(10^7000000000000)

Recall that log(a^b) = b * log(a):

x = 7000000000000 * log2(10)

I get 23253496664212 bits. I would add one or two more just to be safe. Good luck finding the petabytes to hold them, though.

I suspect you are going to need a more interesting algorithm.

暖风昔人 2024-11-23 10:44:41

我想纠正一下回复中所写的一件事:

回想一下 log(a^b) = a * log(b)

它是相反的:

log(a^b) = b * log(a)

I wanna just correct one thing about what was written in the response answer:

Recall that log(a^b) = a * log(b)

well it is the opposite :

log(a^b) = b * log(a)
黄昏下泛黄的笔记 2024-11-23 10:44:41

2^10 = 1024,因此十位将代表略多于三位的数字。既然你谈论的是 7 万亿位数字,那么这大约是 23 万亿位,或者大约 3 TB,这比我上次访问 Costco 的一个驱动器所能获得的还要多。

你可能变得过于雄心勃勃。我想知道每次操作读取和写入整个磁盘的 I/O 时间。

(解决这个问题的数学方法是使用对数,因为需要 7 万亿位数字来表示的数字的对数以 10 为底,约为 7 万亿。找到该数字在现有底数中的对数,转换底数,然后就可以了。对于基数 2 和基数 10 之间的简写,请使用十位 == 三位数,因为它说 2 的对数基数 10 是 0.3,但实际上更像是。 .301。)

2^10 = 1024, so ten bits will represent slightly more than three digits. Since you're talking about 7 trillion digits, that would be something like 23 trillion bits, or about 3 terabytes, which is more than I could get on one drive from Costco last I visited.

You may be getting overambitious. I'd wonder about the I/O time to read and write entire disks for each operation.

(The mathematical way to solve it is to use logarithms, since a number that takes 7 trillion digits to represent has a log base 10 of about 7 trillion. Find the log of the number in the existing base, convert the base, and you've got your answer. For shorthand between base 2 and base 10, use ten bits==three digits, because that's not very far wrong. It says that the log base 10 of 2 is .3, when it's actually more like .301.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文