Bug 19437 – first boolean operation with a double after 'each!' always true

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2018-11-26T13:19:39Z
Last change time
2020-03-21T03:56:37Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Dennis

Comments

Comment #0 by dkorpel — 2018-11-26T13:19:39Z
``` // The magic happens on Windows 32-bit dmd 2.83, no -O/-inline/-m64/Posix/LDC nothrow: pure: @safe: // for good measure struct S { double num; } void main() { import std.algorithm: each; S[] sList = new S[7]; // with 6 the magic won't happen sList.each!(x => x.num); // important double two = 2; // with int the magic won't happen assert(two != two, "A"); assert(two == two, "B"); assert(two != two, "C"); assert(two == two, "D"); } ``` Q: Which of the four assertions throws the AssertError? A: assert C! I came across this when tests curiously failed reporting things like "expected 74, was 74". It seems the first condition involving a double after the each! will be true. In the non-reduced version the each! is even called in a different method. You can also replace assert A with this: ``` if (two != 2) writeln("2 != ", two); ``` And you will see "2 != 2". But only once, you can't duplicate the if-statement and expect the same result.
Comment #1 by b2.temp — 2019-02-14T07:20:20Z
linux 32-bit too (-m32 on x86_64 actually)
Comment #2 by ag0aep6g — 2019-02-14T20:54:05Z
*** This issue has been marked as a duplicate of issue 18573 ***