Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 19, 2011 [Issue 6531] New: assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=6531 Summary: assertion failure in std.range.iota Product: D Version: D2 Platform: Other OS/Version: Windows Status: NEW Severity: major Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: andrej.mitrovich@gmail.com --- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-08-19 07:49:29 PDT --- import std.range; import std.stdio; void main() { auto r1 = iota(0.0, 4.0, 0.03); // ok auto r2 = iota(0.0, 3.0, 0.03); // core.exception.AssertError@std.range(4001): Assertion failure } I want a range in steps of 0.03, beginning at 0.0 and ending at the closest point to 3.0. Line 4001 is: assert(start + count * step >= end); There's no documentation, and no custom assert message, so I don't know what was the intention of the author. It doesn't help that this fails in debug mode but works fine in release mode. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 06, 2012 [Issue 6531] assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=6531 Yao Gomez <yao.gomez@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yao.gomez@gmail.com --- Comment #1 from Yao Gomez <yao.gomez@gmail.com> 2012-02-06 12:48:21 PST --- With DMD 2.058HEAD the assertion is now at line 4136. Doing a little bit of debugging, it seems that the line at 4135: --- if (pastEnd < end) ++count; --- is the culprit. With the r1 range, the count variable is correctly updated, as both pastEnd and end are different. But with the failling range (r2), pastEnd and end have the same value!, and thus the count is not correctly updated. Changing the previous code to: --- if (pastEnd <= end) ++count; --- seems to do the trick, and passes all the std.range unit tests. But I don't know if that's the correct fix. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 06, 2012 [Issue 6531] assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=6531 --- Comment #2 from Yao Gomez <yao.gomez@gmail.com> 2012-02-06 12:51:13 PST --- I have a patch with this solution, but I haven't pulled it yet, because I need more input in whether this is the right fix or not. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 07, 2012 [Issue 6531] assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=6531 dawg@dawgfoto.de changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dawg@dawgfoto.de Depends on| |7455 --- Comment #3 from dawg@dawgfoto.de 2012-02-06 20:27:53 PST --- The correct fix is to narrow the lhs of the comparison. assert(cast(Value)(start + count * step) >= end) It is a common source of bugs that the intermediate 80-bit result is used for temporaries. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 05, 2013 [Issue 6531] assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=6531 --- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-04-05 10:34:42 PDT --- (In reply to comment #3) > The correct fix is to narrow the lhs of the comparison. > assert(cast(Value)(start + count * step) >= end) That doesn't fix the issue. Yao Gomez'es solution does, but I don't know if it's a proper solution. Yao, you could try making a pull request and see if you get more comments on github. Issue 9877 might be a duplicate too. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 06, 2013 [Issue 6531] assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=6531 --- Comment #5 from Martin Nowak <code@dawg.eu> 2013-04-06 01:47:07 PDT --- > if (pastEnd <= end) ++count; This is definitely wrong. There are only 100 steps in [0, 0.03 ..., 3.0). The problem was that assert(0.0 + 100 * 0.03 >= 3.0) fails because of floating-point excess precision. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 11, 2013 [Issue 6531] assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=6531 drug007 <drug2004@bk.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |drug2004@bk.ru --- Comment #6 from drug007 <drug2004@bk.ru> 2013-04-11 07:13:10 PDT --- I propose the following: auto pastEnd = start + count * step; if (step > 0) { if (pastEnd < end) { ++count; pastEnd = start + count * step; } assert(pastEnd >= end); } else { if (pastEnd > end) { ++count; pastEnd = start + count * step; } assert(pastEnd <= end); } Martin Nowak's fix is the better (simpler and more clear) but I just don't like cast. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 11, 2013 [Issue 6531] assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=6531 --- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-04-11 08:13:26 PDT --- (In reply to comment #6) > Martin Nowak's fix is the better (simpler and more clear) but I just don't like > cast. I've tried his fix and it didn't work for me. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 11, 2013 [Issue 6531] assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=6531 --- Comment #8 from drug007 <drug2004@bk.ru> 2013-04-11 08:21:21 PDT --- (In reply to comment #7) > (In reply to comment #6) > > Martin Nowak's fix is the better (simpler and more clear) but I just don't like > > cast. > > I've tried his fix and it didn't work for me. Try mine. It works for me (with your example). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 11, 2013 [Issue 6531] assertion failure in std.range.iota | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=6531 safety0ff.bugz@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |safety0ff.bugz@gmail.com --- Comment #9 from safety0ff.bugz@gmail.com 2013-04-11 09:34:33 PDT --- Indeed, casting does not seem sufficient to force correct rounding of intermediate results. Seems like the solution is to either assign and force rounding, or use approxEqual with appropriate constants for the error terms. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation