Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 kinke <kinke@gmx.net> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |kinke@gmx.net Resolution|--- |INVALID --- Comment #1 from kinke <kinke@gmx.net> --- 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. -- |
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #2 from mw <mingwu@gmail.com> --- It can NOT silently do this, at least a warning. BTW, on Windows, dmd correctly output -2500. -- |
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 mw <mingwu@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|INVALID |--- -- |
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #3 from mw <mingwu@gmail.com> --- Just because C++ did it doesn't means it's correct. And D supposed to be an improvement of C++. -- |
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 FeepingCreature <default_357-line@yahoo.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |default_357-line@yahoo.de --- Comment #4 from FeepingCreature <default_357-line@yahoo.de> --- 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 -- |
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 Basile-z <b2.temp@gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |b2.temp@gmx.com --- Comment #5 from Basile-z <b2.temp@gmx.com> --- I agree too that this is a bug but I think it should be closed as WONTFIX, to keep a certain form of recognition. -- |
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #6 from mw <mingwu@gmail.com> --- 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 -- |
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #7 from kinke <kinke@gmx.net> --- (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. -- |
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 --- Comment #8 from mw <mingwu@gmail.com> --- $ /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 -- |
August 13, 2020 [Issue 21151] div bug: long -5000 / size_t 2 = 9223372036854773308 | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21151 Basile-z <b2.temp@gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code --- Comment #9 from Basile-z <b2.temp@gmx.com> --- 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". -- |
Copyright © 1999-2021 by the D Language Foundation