Reputation:
Say,
base = 2 and e = 20000.5671
How to perform (base power e) for above example in java.
Clearly Math.pow(base, e) is not the way to go as it print's "Infinity"
and BigDecimal accepts 'e' of type int only.
Any other way to achieve this? Expecting more of a JDK library rather than 3p.
Upvotes: 4
Views: 305
Reputation: 525
You can try using exponent product rule.
ab+c = ab * ac
so you can raise 2 to the power of 20000 using the BigDecimal function then multiply by 2 raised to the power 0.5671
This approach will produce an answer that will only be correct to the precision of the least of its parts. The Math.pow
function returns a double, and so is only accurate to around 15 significant figures.
Upvotes: 7
Reputation: 7504
So, there is a mathematical workaround:
BigDecimal.valueOf(2).pow(20000).multiply(BigDecimal.valueOf(Math.pow(2, .5671)))
Upvotes: 1