我可以将Java BigInteger提高为double/float功能吗? [英] Can I raise a Java BigInteger to a double/float power?

查看:182
本文介绍了我可以将Java BigInteger提高为double/float功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是.NET开发人员,但显然.NET中不存在执行此操作的库.因此,Java中是否有任何BigInteger实现可将BigInteger提高到双指数:

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.

推荐答案

尝试一下:

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

但请注意精度问题

您必须导入此库: 导入静态java.lang.Math.pow;

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

这篇关于我可以将Java BigInteger提高为double/float功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆