Summary: | [compiler] Fup of bug 115814, comparing doubles should not be flagged | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Olivier Thomann <Olivier_Thomann> | ||||
Component: | Core | Assignee: | Srikanth Sankaran <srikanth_sankaran> | ||||
Status: | VERIFIED DUPLICATE | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | CC: | amj87.iitr, Olivier_Thomann, srikanth_sankaran | ||||
Version: | 3.4 | ||||||
Target Milestone: | 3.6 M1 | ||||||
Hardware: | PC | ||||||
OS: | Windows XP | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Olivier Thomann
2008-10-17 09:46:47 EDT
Created attachment 115392 [details]
Proposed fix + regression tests
Philippe, please review.
What about 1.0 == 1.0 ? It feels hard to reject all double comparisons because possibility of a NaN ? I will follow up on this, most likely fixed on HEAD. As verified by org.eclipse.jdt.core.tests.compiler.regression.ProgrammingProblemsTest.test0041() we continue to report a diagnostic for 1.0 == 1.0 kind of comparisons. *** This bug has been marked as a duplicate of bug 281776 *** I still get a "comparing identical expressions" warning with this: Double val = 0.1; if(val == val){} though i dont get a warning if i use double instead of Double. Seems like the fix for bug 281776 is insufficient to tackle the wrapper types. Is this intentional? (In reply to comment #5) > I still get a "comparing identical expressions" warning with this: > > Double val = 0.1; > if(val == val){} > > though i dont get a warning if i use double instead of Double. Seems like the > fix for bug 281776 is insufficient to tackle the wrapper types. Is this > intentional? (For the record) Yes, it is. The following program demonstrates the fact that var != var idiom is useful for NaN checking only for primitive floating types and not for references of the wrapper types. In the latter case, we are checking whether the two references don't refer to the same object which is patently false and thus the warning is legitimate. public class X { public static void main(String [] args) { { Double d = Double.NaN; if (d != d) { System.out.println("d != d"); } if (d.isNaN()) { System.out.println("d is Nan"); } } { double d = Double.NaN; if (d != d) { System.out.println("d != d"); } if (Double.isNaN(d)) { System.out.println("d is Nan"); } } } } } Verified for 3.6M7 using I20100425-2000 |