Let's say we have 3 variables:
a,
b and
c
And I'd like an efficient (possibly very tricky) solution to compute "which" of them is the maximum in
magnitude (i.e largest in absolute value). By "which" I mean an ID representing them:
if a is maximum
return 0
else if b is maximum
return 1
else
return 2
end if
Of course, as I said, I need the absolute values. i.e -5 is as large as 5, and therefore both are larger than, let's say, 4. In case two of them are equal, then it really
doesn't matter for me which one is returned, so feel free to adjust the trick how you want in this aspect.
I've been thinking of doing it with
set instructions (you know, after a cmp), but that's just plain too slow. I'm still working on a very tricky way of doing it with "magic" boolean logic operators, but meanwhile I hope you guys help me out.
A floating point implementation is also welcome, but I'm mainly interested in a plain integer one (without SSE/MMX).
of course as a bonus you could also add SSE/MMX or FPU...