4

Possible Duplicate:
How to do a fractional power on BigDecimal in Java?

I have a BigInteger A that I need to exponentiate with 1/b (b is an int).

My problem is that A supports only A.pow(int) which is not suitable for my case.

Is there any workaround for this?

Community
  • 1
  • 1
adrianp
  • 2,491
  • 5
  • 26
  • 44

2 Answers2

2

Newton's method is your jam.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • Newton's method to do scalar exponentiation? Overkill methinks. – David Heffernan Nov 21 '10 at 16:02
  • What is scalar exponentiation? If you take a power 1/b, with b > 1, that becomes a fraction. I haven't worked out if Newton's method becomes something simpler for a case like this, but I doubt that it does. The "classic" Newton example is for b=2 (aka square roots). How do you propose doing this? I don't see a better answer from you. – duffymo Nov 21 '10 at 16:12
  • @David Heffernan - checked out your web site. OrcaFlex looks like a pretty nice product. I used to be a mechanical engineer who used FEA to solve problems in solid mechanics and heat transfer. The problem your code is addressing - non-linear dynamic fluid-structure interaction - is quite challenging. I'd love to know more about it. Some very nice work, indeed. – duffymo Nov 21 '10 at 16:17
  • thanks for the kind words. Actually OrcaFlex is relatively basic in the grand scheme of things but what it does ever so well is to make the job of the engineer simple, efficient and enjoyable. Surprisingly few codes even attempt to do this and that's the main reason why our product is so successful. We also use Newton's method and awful lot!! – David Heffernan Nov 21 '10 at 16:22
0

because BigInteger are intended for Rational numbers, instead fractional powers are Real numbers. http://en.wikipedia.org/wiki/Real_number

The workaround is using a temporary float and then approximate to the nearest BigDecimal.

Uberto
  • 2,712
  • 3
  • 25
  • 27