Can I raise a Java BigInteger to a double/float po

2019-08-13 12:11发布

I'm a .NET developer, but apparently no library exists to do this in .NET. So, is there any BigInteger implementation in Java that allows raising a BigInteger to a double exponent:

BigInteger result = BigInteger.pow( base, dblExponent);
// Base is a BigInteger, dblExponent is a double.

1条回答
放荡不羁爱自由
2楼-- · 2019-08-13 12:15

try this:

BigInteger base = new BigInteger("10");
double base1 = base.doubleValue();
double dblExponent = 10;
double res = pow(base1, dblExponent);
BigDecimal result = new BigDecimal(res);

but pay attention to precision issues

EDIT: you have to import this library: import static java.lang.Math.pow;

查看更多
登录 后发表回答