Ben Bacarisse said:
Oh, OK. It was the testing of LE and LT separately that made me think
you were winding me up. Sorry about that.
I didn't think it was a joke because I seriously thought I'd actually
programmed such a thing somewhere or other. But I can't find a trace of it
now! So my apologies.
The nearest I found was a function that at one time returned 100, 010, or
001 binary, to represent lt, eq, gt, (which I later changed to -1,0,1). And
of course the six comparison codes (eq,ne,lt,le,ge,gt) but encoded as a
6-way linear code, and used as an *input*, not an *output* of any comparison
function.
(Having more than 3 comparison codes as a result of a comparison *is*
possible, but as a set, not a linear value: 3<4 might return (le,lt,ne) for
example. But that requires 6 bits, which could be 'switch'-ed on when
interpreted as a 0..63 code, but not what I had in mind...)
No one can argue against a complaint of "badly defined". Bad how?
Seems fine to me, but obviously not to you.
Because you don't know what value will represent not-equal. A bit like
working out what True is in C.
Obviously, in a HLL you just pass the comparison operator directly, but
in C, you could encode the operator from EQ/LT/GT by using 1<<c+1. (The
precedence rules even avoid the need for brackets: 1<<EQ+1 | 1<<LT+1).
OK, so you'd need to construct a special code (and in practice you would
pre-define the 6 compare codes needed).
The problem I was thinking of, was being given a 6-way relative compare code
(one of eq, lt, etc) and 3-way result of comparison (-1, 0 or 1), then
determining if the result is true for the given compare code.
Obviously that can be sorted out given enough code. However, by using this
set of binary codes (similar to my original proposal, but now used as
input):
EQ=010, NE=101, LT=100, LE=110, GE=011, GT=001.
and making the compare function in it's turn return 100, 010, and 001, then
a simple & operation will tell you if the result matches the desired compare
code.
It was the testing of LE and LT separately that made me think
you were winding me up.
That's not so crazy: X<=Y and X<Y could well have different results. But not
in the exclusive form needed to work in a 6-way switch statement.