Aha - finally, using bitwise or and and: Signed result of [(-x or x) and (-y or y)] is negative it both x and y are non-zero (similar to method 4 below but for whole range any CPU integer bitwidth) On 16 Apr 2014, at 21:45, Warren D Smith wrote:
If x and y both are unsigned integers, and we want to tell whether (x>0 and y>0), then how can we do it?
1. naive method: test x>0 and (if not) then also y>0.
2. x*y>0, but can fail if multiply overflows.
3. The gnu superoptimizer found 44 nonobvious methods, each involving 4 instructions, at least one of which always is subtract-with-borrow and/or add-with-carry. I think the basic idea is: if you regard (x,y) as a 2-digit number, and subtract (1,1), then you will generate at least one borrow if and only if (x=0 or y=0).
4. ((-x)&(-y))>>31 should be nonzero if x>0 and y>0, provided neither x nor y was greater than 2^31 - 1. On a 32-bit machine.
-- Warren D. Smith
_______________________________________________ math-fun mailing list math-fun@mailman.xmission.com http://mailman.xmission.com/cgi-bin/mailman/listinfo/math-fun
The meaning and purpose of life is to give life purpose and meaning. The instigation of violence indicates a lack of spirituality.