Quote:Original post by ZeRaW
nobody replied if mine was correct:
unsigned int MaxValue(unsigned int a1, unsigned int a2)
{
return (bool)(a2/(a1+1))*a2 + (bool)(a1/(a2+1))*a1 + (1-(bool)(a1-a2))*a1;
}
I tested it with a few numbers and it seemed to work.
is type casting to bool acceptable?
I got a divide by zero excpetion when using a = 0xfffffffa, b = 0xffffffff.
If casting is allowed, there is a quite simple solution:
unsigned int myMax(unsigned int a, unsigned int b){ unsigned int za = 1 - (unsigned int)bool(a); unsigned int ma = (unsigned int)bool(b / (a + za)); return (b - a) * ma + a;}