Lots of bool operations shouldn't compile
Thomas Kuehne
thomas-dloop at kuehne.cn
Thu Mar 2 00:20:34 PST 2006
-----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.
# import std.stdio;
#
# int main(){
# creal a = 1;
# creal b = 1i;
#
# writefln("a: %s", a);
# writefln("b: %s", b);
#
# writefln("1 == 1i: %s", (1 == 1i) ? true : false);
# writefln("1 == 0i: %s", (1 == 0i) ? true : false);
# writefln("0 == 1i: %s", (1 == 0i) ? true : false);
# writefln("0 == 0i: %s", (0 == 0i) ? true : false);
#
# return 0;
# }
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) { ... }
The remaining question is: Is the second example unordered (due to the
inan) or ordered?
std.typeinfo.ti_creal._compare(creal, creal): ordered
std.conv.feq(creal, creal): unordered
http://www.digitalmars.com/d/float.html seems silent on this regard.
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFEBqMm3w+/yD4P9tIRAlwnAJ9wYssi82l6Ompor3gKx90+8rCEhQCgycyh
m5cfl2rRa9afNi1dkdL1GeM=
=6QJy
-----END PGP SIGNATURE-----
More information about the Digitalmars-d-bugs
mailing list