I need to find the average of two numbers using only an int as a data type. I cannot use the formula (x1+x2)/2 = mean because that would result in overflow if the numbers are large enough.
I found this formula
int mid = low + ((high - low) / 2);
from this thread Explanation of the safe average of two numbers.
However, this formula does not work when negative numbers are involved. Does anyone have any ideas of how to go about solving this problem? Thanks
Edit - Java