使用GMP进行任意精度算术 [英] Arbitrary precision arithmetic with GMP

查看:188
本文介绍了使用GMP进行任意精度算术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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.

推荐答案

7万亿数字

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

x bits can represent 2^x distinct numbers.

所以你想解决:

2^x = 10^7000000000000

取两边的log-base-2:

Take the log-base-2 of both sides:

x = log2(10^7000000000000)

a ^ b) = b * log(a)

x = 7000000000000 * log2(10)

我得到 23253496664212 位。我会添加一两个只是为了安全。

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.

这篇关于使用GMP进行任意精度算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆