Hi,
I have been with Java for 6 months, yet I got this doubt from a friend... I am posting on behalf of her...
Going directly to the code:
System.out.println(1e-12==Math.pow(10,-12));
System.out.println(1e-5==Math.pow(10,-5));
O/P for the lines of code is:
true
false
I tried:
System.out.println(1e-12);
System.out.println(1e-5);
System.out.println(Math.pow(10,-5));
System.out.println((float)Math.pow(10,-5));
O/P
1.0E-12
1.0E-5
9.999999999999999E-6
1.0E-5
Question is,
I don't know why the O/P of "Math.pow(10,-5)" was "9.999999999999999E-6" but when it was cast into float, it became to "1.0E-5"?
Moreover, it's stranger that, the result of
System.out.println(Math.pow(10,-4)); and System.out.println(Math.pow(10,-6)); are natural, only "Math.pow(10,-5)" has an approximate result? Why?