We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Math.pow(2,63) generates 9223372036854775808 and converting it to long will generate error as the maximum positive value of long can be 9223372036854775807.
So, we will have to generate the correct output by adding Math.pow(2,62) twice and then negating 1 from it to generate the correct positive long value.
The correct code will be as follows -
Java Datatypes
You are viewing a single comment's thread. Return to all comments →
Math.pow(2,63) generates 9223372036854775808 and converting it to long will generate error as the maximum positive value of long can be 9223372036854775807. So, we will have to generate the correct output by adding Math.pow(2,62) twice and then negating 1 from it to generate the correct positive long value. The correct code will be as follows -
if(x>=(long)-Math.pow(2,63) && x<=(long)Math.pow(2,62)+((long)Math.pow(2,62)-1))System.out.println("* long");