www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - opCmp: strange definition in specs

reply Norbert Nemec <Norbert Nemec-online.de> writes:
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
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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