I took a job interview and the following algorithm was asked and I didn’t manage to find out it’s purpose.
int func(int a, int b)
{
int c = b;
while (c <= a)
c <<= 1;
int d = a;
while (d >= b)
{
c >>= 1;
if (c<= d)
d -= c;
}
return d;
}
a < b returns a
,a == b returns 0
,a > b returns ? garbage
.b == 0
anda >= 0
it is an infinite loop.