Can I raise a Java BigInteger to a double/float power?

折月煮酒 提交于 2019-12-11 08:48:47

问题


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:


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;



来源:https://stackoverflow.com/questions/16751167/can-i-raise-a-java-biginteger-to-a-double-float-power

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!