0

I want to do the following in java:

Math.pow((int),(double))

and keep the decimal precision to more than 16 (much greater than that actually).

Is this possible? I know it involves using BigDecimal and maybe ln functions, but I'm not sure how to approach this.

Thanks in advance.

EDIT

The reason I am asking is because I am trying to compute pi to an enormous amount of precision. Currently, I am using Chudnovsky's algorithm. I've tried to use taylor series for this purpose and it takes much too long to be practical.

EDIT

Maybe this is a better question: How do you find the square root of a BigDecimal. (Technically, same as the original since raising to the .5 is...)

Kgrover
  • 2,106
  • 2
  • 36
  • 54
  • You need to find an approximation formula (e.g. Taylor series), and compute it with BigDecimal. – nhahtdh Nov 22 '12 at 05:23
  • Check this out (by Mysticial): http://www.numberworld.org/y-cruncher/algorithms.html – nhahtdh Nov 22 '12 at 05:37
  • @Kgrover If you wanna raise it to a *decimal* power, you might as well start by implementing *exp()* and *log()*. Since a fully generic `a^b` is usually implemented as `e^(b log(a))`. In any case, computing Pi doesn't require a decimal power. – Mysticial Nov 22 '12 at 05:57
  • I am using the Chudnovsky's algorithm: http://en.wikipedia.org/wiki/Approximations_of_%CF%80#20th_century I see that it does need to be raised to the 3/2 power. Is there a faster/easier way to approximate (er- with a lot of precision) pi? – Kgrover Nov 22 '12 at 06:02
  • For square roots, you should use Newton's Method. – Mysticial Nov 22 '12 at 06:10
  • Look at [this](http://stackoverflow.com/questions/3579779/how-to-do-a-fractional-power-on-bigdecimal-in-java) question. – Bernhard Barker Dec 03 '12 at 07:18

0 Answers0