Velocity Reviews > Java > calculating the a bigdecimal to the power of double

# calculating the a bigdecimal to the power of double

manzur
Guest
Posts: n/a

 04-19-2006
I have a bigdecimal and a double value,say

Bigdecimal bd = 599999.45;
double d= 5.9;

i want to do 599999.45^5.9

Note:I dont want to convert bigdecimal to double

Thomas Hawtin
Guest
Posts: n/a

 04-19-2006
manzur wrote:
> I have a bigdecimal and a double value,say
>
> Bigdecimal bd = 599999.45;
> double d= 5.9;
>
> i want to do 599999.45^5.9
>
> Note:I dont want to convert bigdecimal to double

Raising a decimal to the power of 5.9 isn't going to result in a number
expressible as a decimal. If you want more accuracy than provided by
double, I guess you could use a series expansion.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/

Danno
Guest
Posts: n/a

 04-19-2006
I don't think you can xor floating points just integers.

Eric Sosman
Guest
Posts: n/a

 04-19-2006

manzur wrote On 04/19/06 12:15,:
> I have a bigdecimal and a double value,say
>
> Bigdecimal bd = 599999.45;
> double d= 5.9;
>
> i want to do 599999.45^5.9
>
> Note:I dont want to convert bigdecimal to double

Suggestion #1: Convert it to double anyhow, despite

Suggestion #2: Re-examine what you're trying to do.
Is it really a good idea to use a BigDecimal here?

Suggestion #3: Get out your Numerical Methods books
and start writing implementations for transcendental
functions of BigDecimal values, using add() and multiply()
and the other methods of BigDecimal to perform the
underlying arithmetic. (Warning: This will probably not
be a project, but a PROJECT ...)

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

Roedy Green
Guest
Posts: n/a

 04-19-2006
On 19 Apr 2006 09:15:41 -0700, "manzur" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>Bigdecimal bd = 599999.45;
>double d= 5.9;

That won't compile for two reasons.

1. you spelled BigDecimal incorrectly

2. BigDecimal is not a primitive. You need to use a method or
constructor to create a BigDecimal value.
--
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green
Guest
Posts: n/a

 04-19-2006
On 19 Apr 2006 09:59:22 -0700, "Danno" <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>I don't think you can xor floating points just integers.

He means ^ to represent power.
--
http://mindprod.com Java custom programming, consulting and coaching.

Patricia Shanahan
Guest
Posts: n/a

 04-19-2006
manzur wrote:
> I have a bigdecimal and a double value,say
>
> Bigdecimal bd = 599999.45;
> double d= 5.9;
>
> i want to do 599999.45^5.9
>
> Note:I dont want to convert bigdecimal to double
>
>

As already said, non-integer powers in BigDecimal would be a significant
project.

Maybe there is a less drastic solution to your problem. Could you
explain why you don't want to do the power calculation in double? That
may give someone ideas for alternatives.

Patricia

Danno
Guest
Posts: n/a

 04-20-2006
There must've been some invisible thing on there. hehe

EJP
Guest
Posts: n/a

 04-20-2006
Patricia Shanahan wrote:
>
> As already said, non-integer powers in BigDecimal would be a significant
> project.

Indeed. I implemented it years ago for a COBOL compiler and it took
several weeks. Even finding the constants for the polynomials is a
project in itself: for example, they are in a book which is out of print
and selling for large enough prices that I don't want to name it or
you can compute them yourself but then you have just started several
*more* projects.

Danno
Guest
Posts: n/a

 04-20-2006
Ah, the title!

****, I never look there.