Skip to content

Commit

Permalink
Replaced subtraction based comparison. When the difference (which is …
Browse files Browse the repository at this point in the history
…a double) is converted to an integer the result may overflow. This overflow can occur in rare cases but would cause the comparator to be non-transitive.

Change-Id: Ic7deea389f63273202288e6d11cc19af94f08d63
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Dec 12, 2012
1 parent 40536af commit 425c795
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -600,7 +600,11 @@ public List equivalenceClasses() {
SimpleCycle[] cyclesArray = cycles.toArray(new SimpleCycle[cycles.size()]);
Arrays.sort(cyclesArray, new Comparator<SimpleCycle>() {
public int compare(SimpleCycle o1, SimpleCycle o2) {
return (int) ((o1).weight() - (o2).weight());
if(o1.weight() > o2.weight())
return +1;
if(o1.weight() < o2.weight())
return -1;
return 0;
}
});

Expand Down

0 comments on commit 425c795

Please sign in to comment.