BigDecimal to power of BigDecimal

Discussion in 'Java' started by czarnysfetr@gmail.com, Feb 5, 2007.

  1. Guest

    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
     
    , Feb 5, 2007
    #1
    1. Advertising

  2. Eric Sosman Guest

    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
     
    Eric Sosman, Feb 5, 2007
    #2
    1. Advertising

  3. 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
     
    Patricia Shanahan, Feb 5, 2007
    #3
  4. Guest

    Thanks a lot, problem vanished :)
     
    , Feb 5, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Forrest Hump
    Replies:
    4
    Views:
    24,391
    Mark Meyer
    Aug 22, 2003
  2. Cory Musselman

    Problems with XMLEncoder and BigDecimal

    Cory Musselman, Oct 30, 2003, in forum: Java
    Replies:
    0
    Views:
    2,305
    Cory Musselman
    Oct 30, 2003
  3. manzur
    Replies:
    14
    Views:
    7,621
    andyt
    Dec 16, 2010
  4. Replies:
    8
    Views:
    387
    Mark Dickinson
    Apr 17, 2008
  5. Stanimir Stamenkov
    Replies:
    4
    Views:
    2,635
    Stanimir Stamenkov
    Jul 18, 2008
Loading...

Share This Page