Lots of bool operations shouldn't compile

Kyle Furlong kylefurlong at gmail.com
Thu Mar 2 01:40:06 PST 2006


Don Clugston wrote:
> Thomas Kuehne wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Don Clugston schrieb am 2006-02-28:
>>
>> [snip]
>>
>>> OK, there's another bug in there, comparing an int with an imaginary 
>>> real should also not be legal.
>>>
>>>      if (1 > -2i) { assert(0); }
>>>      if (1 > ireal.nan) { assert(0); }
>>>
>>> Reals and ireals cannot be compared. Ever.
>>
>> Sure you can. Floats and imaginary floats can both be implicitly promoted
>> to complex floats.
> 
> That only gives you == and !=.
> 
> <snip>
>> Thus
>>
>>>      if (1 > -2i) { assert(0); }
>>>      if (1 > ireal.nan) { assert(0); }
>>
>> are interpreted as
>>
>>>      if (1 + 0i > 0 - 2i) { ... }
>>>      if (1 + 0i > 0 + ireal.nan) { ... }
> 
> Yes, but that still doesn't work, there's no > for complex numbers.
> Is  2 - 3i > 3 - 2i ?

One could speak of their magnitudes, I suppose.

creal i = 2 - 3i;
creal j = 3 - 2i;

real i_m = sqrt(i * complexConjugate(i));
real j_m = sqrt(j * complexConjugate(j));

but then I guess you are just comparing reals.



More information about the Digitalmars-d-bugs mailing list