I'm trying to calculate the cube root of a number to check if it's a perfect cube. Unfortunately the .NET Framework has no built-in function for that. So in order to calculate the cube root of a number I have to use the Math.Pow
function:
double cubeRoot = Math.Pow(125, (double)1 / 3);
When I try to evaluate if the cube root is an integer it outputs false
, yet 125 is a perfect cube:
Console.WriteLine(cubeRoot % 1 == 0);
How can I overcome this issue?