A Fresh Look at Comparisons, Take 2
Janice Caron
caron800 at googlemail.com
Sat Apr 19 01:38:32 PDT 2008
On 19/04/2008, Henning Hasemann <hhasemann at web.de> wrote:
> > if (c.im == 0 && d.im == 0 && c.re < d.re)
>
> so 2i >= 5 would hold?
No. That assertion is false.
2i < 5 is false
2i == 5 is false
2i > 5 is false
In general, for complex c and d, if you want to less for >=, you would do
if (c.im == 0 && d.im == 0 && c.re >= d.re)
Basically the rule is, if both numbers are not completely real, then
they are not comparable, and > and < will both always yield false.
(And I'm talking math here - implementation in a programming language
might be different - e.g. you might throw an exception instead of
returning false, or you might decide to make them incomparable
regardless of the real subset).
> The point is that you might want to create structures that are more
> complex and not that linear ordered.
I assume you mean "partially ordered"?
Yes, that's true. But remember, partially ordered types cannot be used
as AA keys (at least, not if the AA is implemented as a binary tree
with total ordering), so we've got a problem right there. How do we
tell AAs "Yes, we've implemented opCmp(), but you're not allowed to
use it because it's partial"?
More information about the Digitalmars-d
mailing list