top | item 33895396

(no title)

pksadiq | 3 years ago

> x/2 + y/2 + (x & y & 0x01)

This returns -1 for x = INT_MIN and y = INT_MAX were the answer should be 0 (for an example). so not a correct solution

discuss

order

slymon99|3 years ago

Isn't (32 bit) INT_MAX 2^31-1 and INT_MIN -2^31, so this is an acceptable solution (since the decimal average is -0.5)?

pksadiq|3 years ago

> since the decimal average is -0.5

The C standard says: When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded (This is often called ‘‘truncation toward zero’’).

So it should be 0 (as per C standard, not sure what C++ standard says)