user12318711
user12318711

Reputation:

How to do exponentiation e when 'e' is decimal for very large numbers of e?

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

Answers (2)

Aaron Hayman
Aaron Hayman

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

Note :-

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

Vinay Prajapati
Vinay Prajapati

Reputation: 7504

So, there is a mathematical workaround:

BigDecimal.valueOf(2).pow(20000).multiply(BigDecimal.valueOf(Math.pow(2, .5671)))

Upvotes: 1

Related Questions