Two floating-point numbers cannot be accurately compared with "= =" floating-point numbers can only be close to not equal
if (0.1+0.2==0.3) {
System.out.println (TRUE);
}
Rounding is never done when floating-point numbers are generated the overflow data loss results in inaccurate data and cannot be directly performed on = = Operations
Workaround: Use integers, not floating-point numbers
2. Problem with floating points in operation
1. 1/a will appear floating-point number two integer division value Loss problem
for (int a=20; a>=1;a–) {
for (int b=a-1; b>=1;b–) {
for (int c=b-1; c>=1;c–) {
for (int d=c-1; c>=1;d–) {
if (1/a+1/b+1/c+1/d==1) {
System.out.println (A +, "+b+", "+c+", "+d");
}
}
}
}
}
Error
1. integer division values are lost by
2. Floating point numbers cannot be accurately compared,
Solution:
1. Formula conversion b*c*d+a*c*d +a*b*d+a*b*c==a*b*c*d
2. Subtract compared to one of the precision values
eg: a-b<c A, b comparison