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
  • 36,732
  • 85
  • 259
  • 481

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,516
  • 4
  • 17
  • 25