"Comparing identical expressions" [message #542578] |
Fri, 25 June 2010 07:11  |
Eclipse User |
|
|
|
In Eclipse 3.5.2 I get the following warning for
my comparator for doubles (offending lines marked with
a # in a comment):
public int compare(double x1, double x2) {
if (x1 < x2)
return -1;
if (x1 > x2)
return 1;
if (x1 != x2) {
if (x1 == x1) { // #1
return 1;
}
if (x2 == x2) { // #2
return -1;
}
}
return 0;
}
IMO this is a misleading diagnostic, because for
floating-point types all branches within this
test function can be reached. This is, so because
there can be NaN values tested. The reason for the whole
"if (x1 != x2)" block is to order NaN's relative to
non-NaN's. In Java it is guaranteed that an NaN values
evaluates != to true for *all* values, including
other NaNs.
In principle I like the warning category and would prefer
to switch it off locally, if possible, unfortunately
there seems not exist any SuppresWarning directive for
this one.
Any ideas how to get rid of the warning w/o switching
the category completly off? (And yes, I'm already using
project-specific warnings).
Thanks & Greetings from Bremen,
Daniel Krügler
|
|
|
|
Powered by
FUDForum. Page generated in 0.05443 seconds