Arbitrary precision arithmetic with GMP

前端 未结 3 1090
梦谈多话
梦谈多话 2021-01-26 14:38

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 de

3条回答
  •  一生所求
    2021-01-26 15:28

    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.

提交回复
热议问题