digitalmars.D.bugs - [Issue 5565] New: [64-bit] Wrong Floating Point Results, Related to Mixing With size_t
- d-bugmail puremagic.com (43/43) Feb 11 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5565
- d-bugmail puremagic.com (8/8) Feb 11 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5565
- d-bugmail puremagic.com (13/13) Feb 12 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5565
- d-bugmail puremagic.com (18/18) Feb 12 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5565
- d-bugmail puremagic.com (12/12) Feb 12 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5565
http://d.puremagic.com/issues/show_bug.cgi?id=5565 Summary: [64-bit] Wrong Floating Point Results, Related to Mixing With size_t Product: D Version: D2 Platform: x86_64 OS/Version: Windows Status: NEW Keywords: wrong-code Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: dsimcha yahoo.com --- Comment #0 from David Simcha <dsimcha yahoo.com> 2011-02-11 22:06:07 PST --- The following code produces erratic results. I don't know where exactly the culprit is, but I'm hoping I've reduced it enough that someone with a decent mental model of how the compiler works will be able to finish the job. import std.stdio; double foo(int[] data, double q = 0.25) { immutable double N = data.length; // This actually affects the result, making it more severe and obvious // in addition to showing that the value is correct. stderr.writeln(N); // Prints 8. Correct. // lowEnd should be floor(7 * 0.25) == 1. immutable lowEnd = cast(size_t) ((N - 1) * q); // highEnd should be floor(7 * 0.75) - 1 = 4. immutable highEnd = cast(size_t) ((N - 1) * (1.0 - q) - lowEnd); // highFract should be 7 * 0.75 - 4 - 1 = 0.25 immutable highFract = (N - 1) * (1.0 - q) - lowEnd - highEnd; stderr.writeln(lowEnd, '\t', highEnd, '\t', highFract); return highFract; } void main() { writeln(foo([1,2,3,4,5,6,7,8])); } Prints: 8 0 4545916 -4.54591e+06 -4.54591e+06 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 11 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5565 --- Comment #1 from David Simcha <dsimcha yahoo.com> 2011-02-11 22:08:48 PST --- Forgot to mention: This test case doesn't reproduce the bug if -O is enabled, though the test case I reduced it from did, I think. (I'm not 100% sure that I wasn't just seeing two different bugs simultaneously.) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 11 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5565 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla digitalmars.com Resolution| |FIXED --- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2011-02-12 15:04:22 PST --- https://github.com/D-Programming-Language/dmd/commit/95b70d83ac51496eb171c1b408b5781eeee1a29d https://github.com/D-Programming-Language/dmd/commit/fe147641a0334bca8d5ac3def7a0aba8529a0a66 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 12 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5565 David Simcha <dsimcha yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|FIXED | --- Comment #3 from David Simcha <dsimcha yahoo.com> 2011-02-12 15:37:05 PST --- I think this was actually two bugs that I thought had a single root cause. You only got one of them. Now, the result from running this code with -m64 and without -O on linux is: 8 1 4545912 -4.54591e+06 -4.54591e+06 On the line with the three columns, the first one is now correct. The other two are still wrong, unless -O is enabled. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 12 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5565 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |RESOLVED Resolution| |FIXED --- Comment #4 from Walter Bright <bugzilla digitalmars.com> 2011-02-12 21:57:02 PST --- https://github.com/D-Programming-Language/dmd/commit/2421fd325b8e7528f5bafd2c4a4d6fd5008f3ab1 https://github.com/D-Programming-Language/dmd/commit/c51de3ab026f811744a4dc81b6f50c2525fc07a5 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 12 2011