Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > BigDecimal to power of BigDecimal

Reply
Thread Tools

BigDecimal to power of BigDecimal

 
 
czarnysfetr@gmail.com
Guest
Posts: n/a
 
      02-05-2007
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

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      02-05-2007
wrote:
> 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 ...

--
Eric Sosman
lid
 
Reply With Quote
 
 
 
 
Patricia Shanahan
Guest
Posts: n/a
 
      02-05-2007
Eric Sosman wrote:
> wrote:
>> 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 ...
>


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
 
Reply With Quote
 
czarnysfetr@gmail.com
Guest
Posts: n/a
 
      02-05-2007
Thanks a lot, problem vanished

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calculating the a bigdecimal to the power of double manzur Java 14 12-16-2010 03:35 PM
BigDecimal(String) vs. BigDecimal(double) [Floating-point arithmetics] Stanimir Stamenkov Java 4 07-18-2008 10:49 AM
High Power 560Watt Power Supply HPC-560-A12C @ ThinkComputers.org Silverstrand Front Page News 0 02-21-2006 10:25 PM
AOpen Prima Power AO700-12ALN 700W Power Supply Review Silverstrand Front Page News 5 08-29-2005 11:38 AM
HEC Ace Power 580UB 580Watt power supply Silverstrand Front Page News 0 07-23-2005 03:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57