In Java, why are the following results different?
Double:
double x1 = 279_632_249;
double a1 = (x1 * x1);
System.out.println(printDouble(a1)); // 78194194680798000
Long:
long x2 = 279_632_249;
long a2 = (x2 * x2);
System.out.println(a2); // 78194194680798001
Utility function
private static String printDouble(double d) {
BigDecimal bigDecimal = new BigDecimal(Double.toString(d));
return bigDecimal.toPlainString();
}
Numbers greater than 279_632_249 will also differ. Is there a limit at 279_632_248?