为什么 JAVA 中的 BIGInteger 对更高的幂没有响应?

发布于 2024-07-25 03:41:33 字数 211 浏览 2 评论 0原文

当我尝试查找 223,000BigInteger 数据类型的值时,我看不到该值。

但是,对于高达 222,000 的计算,我可以毫无问题地显示 BigInteger 值。

有什么解决办法或者原因吗?

When I try to find the value of a BigInteger data type for 223,000, I am not able to see the value.

However, for calculations up to 222,000, I could display the BigInteger value without any problems.

Is there any solution or reason for this?

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

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

发布评论

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

评论(4

风追烟花雨 2024-08-01 03:41:33

我尝试了以下方法来制作 2^23000BigInteger 表示:

BigInteger bi = new BigInteger("2");
bi = bi.pow(23000);
System.out.println(bi);

并且显示的数字是一个非常大的数字,跨越 6925 位。 (我不会将其粘贴到此处,因为它将跨越 100 行。)

这是 Windows XP 中的 Java 6 SE 版本 1.6.0_12。

根据 API 规范,BigInteger 是一个任意精度的整数值,这意味着它应该能够处理非常大的整数值。

I tried the following in order to make a BigInteger representation of 2^23000:

BigInteger bi = new BigInteger("2");
bi = bi.pow(23000);
System.out.println(bi);

And the number displayed was a very large number spanning 6925 digits. (I won't paste it here as it will span over 100 lines.)

This is with Java 6 SE version 1.6.0_12 in Windows XP.

According the API Specification, BigInteger is an arbitrary-precision integer value which means it should be able to cope with very large integer values.

青衫负雪 2024-08-01 03:41:33

它在 GNU/Linux 上对我来说工作得很好。 您无法“显示”它是什么意思? 您的代码是什么以及您遇到什么错误/问题?

It works fine for me on GNU/Linux. What do you mean you can't "display" it? What's your code and what error/problem do you get?

柏林苍穹下 2024-08-01 03:41:33

BigInteger 的此限制约为 2^160 亿,但有人指出,某些函数在大约 2^20 亿之后无法正常运行。

我的猜测是您的控制台或 IDE 在显示很长的行时出现问题。

this limit for BigInteger is around 2^16 billion, though it has been noted that some functions don't behave correctly after about 2^2 billion.

My guess is that your console or IDE has problems displaying very long lines.

小巷里的女流氓 2024-08-01 03:41:33

你需要整件事吗? 还有一个 BigInteger.modpow(power, modulus) 方法,它将整数值提高到指定的幂并返回结果 % modulus —— 常用于密码学。 当处理非常大的指数时,这也会快得多。

Do you need the whole thing? There is also a BigInteger.modpow(power, modulus) method which raises the integer value to the specified power and returning result % modulus -- commonly used in cryptography. This is also MUCH faster when dealing with very large exponents.

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