Search code examples
javabigdecimalexponential

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.


Solution

  • 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.