While writing a program, I came across a search for the root of a number cube in one of my functions.
when I used the code below, I got the wrong value for the root of the cube ( 1 printed for n = 64 ).
public static void cubicPairs(double n) { double root = (System.Math.Pow(n, (1/3))); Console.WriteLine(root); }
Now that I have changed the code a bit,
public static void cubicPairs(double n) { double root = (System.Math.Pow(n, (1.0/3.0)));
I got root = 3.9999999999999996 (when debugging), but this method printed 4 (this is correct).
Why is there a difference between the two values, and if this is related to the second parameter of the System.Math.Pow() method (i.e. 1.0/3.0 , which is a recursive value), what should I use to find the root of the cube, so what I get 4 (when debugging), not 3.9999999999999996 ?
source share