PB.DCF
Do not compare floating point types
Description
This rule flags code that compares floating point types.
Comparing floating point numbers for equality can cause logic errors or infinite loops due to unexpected results.
Example
package PB;
public class DCF {
int method (double d) {
if (d == 1) {
return 1;
} else if (d != 2) {
return 2;
} else return 3;
}
}
Repair
Use the comparison of floating point numbers sparingly.
|