BigDecimal to power of BigDecimal

C

czarnysfetr

Hi,

I have a problem with calculating expression, in which I have to use

BigDecimal1 ^ BigDecimal2


BigDecimal.pow() isn't suitable - as far as I know, it requires int as
an parameter, and both my numbers are BigDecimals.


Does anyone know how to handle it?

sfetr
 
E

Eric Sosman

Hi,

I have a problem with calculating expression, in which I have to use

BigDecimal1 ^ BigDecimal2


BigDecimal.pow() isn't suitable - as far as I know, it requires int as
an parameter, and both my numbers are BigDecimals.


Does anyone know how to handle it?

bd1.pow(bd2.intValue()) looks like a good starting point.
If bd2 has a fractional part, you'll need to work harder --
perhaps Math.pow(bd1.doubleValue(), bd2.doubleValue()) would
be of use, followed by conversion from double to BigDecimal.

Seems like a strange thing to want to do, though. I hope
you've got lots of memory ...
 
P

Patricia Shanahan

Eric said:
bd1.pow(bd2.intValue()) looks like a good starting point.
If bd2 has a fractional part, you'll need to work harder --
perhaps Math.pow(bd1.doubleValue(), bd2.doubleValue()) would
be of use, followed by conversion from double to BigDecimal.

Seems like a strange thing to want to do, though. I hope
you've got lots of memory ...

Even if the double approach does not give enough accuracy, it might be a
good starting point for an iterative improvement algorithm such as
Newton-Raphson.

However, it definitely needs to be dome carefully, with attention to
trade-offs between accuracy and memory.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top