Quantcast
Channel: Signed integer comparison without comparison operators or widening - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Signed integer comparison without comparison operators or widening

$
0
0

I am looking for a signed integer comparison function cmp(x: Int, y: Int) -> Int which does not use any comparison operators (<, <=, >, >=, <=>, etc.), does not use widening to a larger size of integer, and ideally only uses addition, subtraction, bitwise operators and the equality and inequality operators (==, !=).

I have tested the comparison operators here, here and here, but all of them fail for certain input values (here is a test program in Rust). The first two seem the most promising, and they fail for the same values, probably because of underflow in the subtraction.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images