如何进行大数运算

问题描述 投票:0回答:2

我需要计算比长整数可以存储的数字大得多的数字(例如1234567890 * 1234)。有什么方法可以超过该内存容量?

java long-integer
2个回答
0
投票

您可以使用:

BigInteger num= new BigInteger("1234567890*1234");

0
投票

如果要坚持使用纯Java,则可以使用BigInteger,但可以使用jscience。这是一个很棒的图书馆,针对这些问题进行了大量的优化。

也许这堂课,LargeInteger,对你有好处。

Here是适合您的示例:

LargeInteger dividend = LargeInteger.valueOf("3133861182986538201");
LargeInteger divisor = LargeInteger.valueOf("25147325102501733369");
Rational rational = Rational.valueOf(dividend, divisor);
System.out.println("rational  = " + rational);

> rational  = 41/329
© www.soinside.com 2019 - 2024. All rights reserved.