Consider this program to determine if a given number is a power of 2.
class Solution{
// Function to check if given number n is a power of two.
public static boolean isPowerofTwo(long n){
// Your code here
float x = (float)Math.log(n)/(float)Math.log(2);
System.out.println(x);
if(x%1==0)
return true;
return false;
}
}
Then consider n =1073741824, while the output should be 30,it gives 29.999998.