0

I need to calculate x^y where both x and y are Doubles.

I tried using Math.Pow:

  Double result = Math.Pow(24.69, 2/3);

The value of result is 1 where it should be 8.4790 ...

Any idea why?

Miguel Moura
  • 32,822
  • 74
  • 219
  • 400

1 Answers1

3

For the exponent you are passing in 2 ints which is do integer division. So it is doing:

Math.Pow(24.69, 0)

To fix this use doubles like this:

Double result = Math.Pow(24.69, 2.0/3.0);
Tom Dee
  • 2,358
  • 4
  • 15
  • 22