I'm trying to use Java to calculate the value of the value of 2^{61} - 1.
Here's my code
import java.lang.Math;
class Main {
public static void main(String[] args) {
long x = (long) (Math.pow(2, 61) - 1);
System.out.println(x);
}
}
The output is 2305843009213693952, which is wrong.
The answer should be 2305843009213693951.
I'm confused as to why this is the case?
Thanks