How to do a fractional power on BigDecimal in Java?

Viewed 25357

In my little project, I need to do something like Math.pow(7777.66, 5555.44) only with VERY big numbers. I came across a few solutions:

  • Use double - but the numbers are too big
  • Use BigDecimal.pow but no support for fractional
  • Use the X^(A+B)=X^A*X^B formula (B is the remainder of the second num), but again no support for big X or big A because I still convert to double
  • Use some kind of Taylor series algorithm or something like that - I'm not very good at math so this one is my last option if I don't find any solutions (some libraries or formula for (A+B)^(C+D)).

Does anyone know of a library or an easy solution? I figured that many people deal with the same problem...

p.s. I found some library called ApFloat that claims to do it approximately, but the results I got were so approximate that even 8^2 gave me 60...

3 Answers

The big-math library released under MIT license has a simple static helper BigDecimalMath.log(BigDecimal, MathContext) for log and many other functions not included with BigDecimal. Very simple to use and has lots of benchmarking data to compare performance.

Related