Math.pow()
is returning an unexpected result for some inputs.
for ex - below is my code to find the nth root of m
public class FindRoot {
static int m,n;
public static void main(String[] args) {
findRoot(m,n);
}
private static void findRoot(int m, int n) {
double tempDouble = Math.pow(m, 1.0/n);
System.out.println(tempDouble);
}
}
Now, when i pass m = 9 & n = 2, it is giving expected result i.e. 3.0 but if i pass m = 1000 & n = 3 then i am expected 10.0 but it is giving 9.999999999999998 i.e. unexpected result.