简体   繁体   English

具有两个cpp_int值的boost :: multiprecision :: pow

[英]boost::multiprecision::pow with two cpp_int values

Is there a way to use boost::multiprecision::pow with two cpp_int values as the parameters? 有没有办法使用带有两个cpp_int值作为参数的boost :: multiprecision :: pow? All I can find in the documentation has the parameters of type cpp_int for the base and int for the exponent. 我在文档中可以找到的所有参数的基本类型为cpp_int,指数类型为int。 This seems very limiting. 这似乎是非常有限的。

Comment: How is that limiting? 评论:这有何限制? Will you be raising to powers above MAXINT? 您会提高到MAXINT以上的功率吗? How? 怎么样?

Q :
What do you mean 'how'? 你是什​​么意思? Isn't the point of multiprecision libraries to handle enormous numbers like this? 多元精度库不是要处理这样的大量数字的目的吗?

No. Enormous numbers like this rarely make any sense at lossless precisions. 不会。如此庞大的数字很少会对无损精度产生任何意义。

Lets say we start out with a reasonably small number, like 10 . 可以说我们从一个很小的数字开始,例如10 The smallest exponent that doesn't fit in a 64-bit integer would be 2^64. 不适合64位整数的最小指数为2 ^ 64。 So, the number is 10^(2^64), which is roughly 18446744073709551617 decimal digits ≈ 1.84467×10^19 decimal digits. 因此,该数字是10 ^(2 ^ 64),大约是18446744073709551617十进制数字≈1.84467×10 ^ 19十进制数字。

To print that you'd need paper weighing roughly 1.4757×10^11 metric tons, assuming 5,000 digits per 80g page . 要打印,您需要重约1.4757×10 ^ 11公吨的纸张(假设每80g页5,000位) That's roughly the equivalent of total biomass on Earth (≈ 8×10^13 kg). 这大约相当于地球上总生物量(≈8×10 ^ 13 kg)。

Now, of course you're not silly, and you won't print it! 现在,您当然并不傻,也不会打印出来! You only need to fit it in RAM, which is why you have started crowd funding for your 7.6598 exabytes of RAM. 您只需要在RAM中安装它,这就是为什么您开始为7.6598 EB RAM进行众筹的原因。 Not to mention the power supply for it, because powering that for one hour will cost take around 7 gigawatt hours, which is comparable to half the energy yield of Little Boy nuclear bomb. 更不用说它的电源了,因为供电一小时将花费大约7吉瓦时,这相当于小男孩核弹能量产出的一半。

What Can You Do 你能做什么

Boost Multiprecision does allow you to use exact and lossless representation of huge integral number, but the resources of your systems limit the total capacity. Boost Multiprecision 确实允许您使用巨大的整数精确无损地表示,但是系统的资源限制了总容量。

As shown, exponents exceeding 64 bit integers are not sensible for these types. 如图所示,对于这些类型,超过64位整数的指数是不明智的。

You can, of course, use a decimal/binary floating point representation at arbitrary precision (still honouring the constraints of physics and economics, of course), like boost::multiprecision::mpf_float_1000 . 当然,您可以使用任意精度的十进制/二进制浮点表示法(当然, boost::multiprecision::mpf_float_1000物理和经济学的约束),例如boost::multiprecision::mpf_float_1000

您可以使用boost :: multiprecision :: float和相应的boost :: multi precision :: pow实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM