Jtest logo




Contents  Previous  Next  Index

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.


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft