I want to calculate x power y and both x,y are double values. Why is java giving me a compilation error? What is the best way to do so?
I am currently using the following method:
x^y // attempt to calculate (x pow y)
Thanks.
I want to calculate x power y and both x,y are double values. Why is java giving me a compilation error? What is the best way to do so?
I am currently using the following method:
x^y // attempt to calculate (x pow y)
Thanks.
The simplest way to implement it remains, as always:
Take the logarithm (base 10) of x; multiply it by y, and take the inverse logarithm (base 10) of the result to get x pow y.
To simply calculate it, Math.pow(x,y);
, as has been pointed out.
See the Math class. It has a static function pow, which accepts double values as arguments.