[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 Iain Buclaw changed: What|Removed |Added Priority|P3 |P2 --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #12 from mw --- for the additional reference, the forum discussion is here: https://forum.dlang.org/thread/rdrqedmbknwrppbfi...@forum.dlang.org Now both Java and C# did it more correct than D. """ At least I want a warning message, even with a turn-on command-line switch is fine, I personally will turn it on all the time, silently performing this conversions is horrible. In many area of the language design, we need to make a choice between: correctness v.s. raw performance. But at least we also need *explicit* visible warning message after we've made that choice: -- especially warnings about *correctness* when the choice was made favoring performance -- if the choice was made favoring correctness, user will notice the performance when the program runs. Personally, I will favor correctness over performance in my program design decisions: make it correct first, and faster later; you never know before-hand where your program's bottleneck is. I'm sure you know the famous quote: "Premature optimization is the root of all evil!" """ --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #11 from kinke --- FWIW, in C# this is an error: long a = -5000; ulong b = 2; long c = a / b; // Operator '/' is ambiguous on operands of type 'long' and 'ulong' --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 kinke changed: What|Removed |Added Keywords|wrong-code |spec Hardware|x86_64 |All OS|Linux |All --- Comment #10 from kinke --- Removing the wrong-code tag, as code adhering to the spec isn't wrong. --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 Basile-z changed: What|Removed |Added Keywords||wrong-code --- Comment #9 from Basile-z --- Werll after the new facts about the behavior on i386 I retire what I said ealier. This should not be closed. Tagged it as "wrong code". --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #8 from mw --- $ /mnt/c/project/dmd2/windows/bin64/dmd.exe --version DMD64 D Compiler v2.092.0-dirty Copyright (C) 1999-2020 by The D Language Foundation, All Rights Reserved written by Walter Bright --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #7 from kinke --- (In reply to mw from comment #2) > BTW, on Windows, dmd correctly output -2500. Not on Windows, but for 32-bit targets, as an unsigned 32-bit int is converted to a signed 64-bit long in that case, according to spec 6.8.1.4.3. --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #6 from mw --- OK, let me write this in this way to show it's impact: == import std.algorithm; import std.stdio; void main() { long[] a = [-5000, 0]; long c = sum(a) / a.length; writeln(c); } == $ ./divbug 9223372036854773308 --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 Basile-z changed: What|Removed |Added CC||b2.t...@gmx.com --- Comment #5 from Basile-z --- I agree too that this is a bug but I think it should be closed as WONTFIX, to keep a certain form of recognition. --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 FeepingCreature changed: What|Removed |Added CC||default_357-l...@yahoo.de --- Comment #4 from FeepingCreature --- I'm completely on mw's side here, even understanding why D does this. Silently casting negative signed to unsigned violates the foundational principle that at least on built-in types, implicit conversions should never throw away data. Though I think it should be a spec enhancement issue, to correct 6.8.1.4.4: "The signed type is converted to the unsigned type." https://dlang.org/spec/type.html#usual-arithmetic-conversions --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #3 from mw --- Just because C++ did it doesn't means it's correct. And D supposed to be an improvement of C++. --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 mw changed: What|Removed |Added Status|RESOLVED|REOPENED Resolution|INVALID |--- --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #2 from mw --- It can NOT silently do this, at least a warning. BTW, on Windows, dmd correctly output -2500. --
[Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308
https://issues.dlang.org/show_bug.cgi?id=21151 kinke changed: What|Removed |Added Status|NEW |RESOLVED CC||ki...@gmx.net Resolution|--- |INVALID --- Comment #1 from kinke --- This is a usual arithmetic conversion, see https://dlang.org/spec/type.html#usual-arithmetic-conversions. C++ does the same, see https://cpp.godbolt.org/z/YGnr44. --