I am trying to square a number x but there seems to be some discrepancy in precision while squaring it using Math.pow() and squaring it using multiplication.
public class MyClass {
public static void main(String args[]) {
long x = 1250075001;
System.out.println(x*x);
System.out.println(Math.pow((double)x,2.0));
}
}
OUTPUT:
1562687508125150001
1.56268750812514995E18
The deviation is both the results in shown in bold
1562687508125150001
1.56268750812514995E18
I am not an expert in double arithmetic and how Math.pow() function works.
I tried reading some online articles on IEEE double standard and Math.pow() but it didn't help and that's why I came to the Stack Overflow community.