digitalmars.D - opCmp: strange definition in specs
- Norbert Nemec (8/8) Mar 08 2010 I just read through the specs about operators and found a strangeness in...
- Steven Schveighoffer (41/49) Mar 08 2010 From testing (dmd 2.040) it appears that the spec is wrong (the correct...
I just read through the specs about operators and found a strangeness in the definition of opCmp: http://www.digitalmars.com/d/2.0/operatoroverloading.html#compare Mathematically the following are equivalent a < b <=> b > a But the definition seems to swap a < b into b >= a I have not tested the compiler about this yet...
Mar 08 2010
On Mon, 08 Mar 2010 06:15:16 -0500, Norbert Nemec <Norbert nemec-online.de> wrote:I just read through the specs about operators and found a strangeness in the definition of opCmp: http://www.digitalmars.com/d/2.0/operatoroverloading.html#compare Mathematically the following are equivalent a < b <=> b > a But the definition seems to swap a < b into b >= a I have not tested the compiler about this yet...From testing (dmd 2.040) it appears that the spec is wrong (the correct thing is done). I'm amazed this was never caught, I think it's been this way for a long time. Good catch, you should file a bug. test code: import std.stdio; struct S { } struct T { int opCmp(S s) { return 0; } } void main() { S s; T t; writeln(s < t); writeln(t < s); writeln(s <= t); writeln(t <= s); writeln(s > t); writeln(t > s); writeln(s >= t); writeln(t >= s); } outputs: false false true true false false true true -Steve
Mar 08 2010