different ways to find middle point in a range I've found that in some algorithms to find the middle point of a numeric range the next formula is used:
middle = low + ((high - low) / 2)

Yet, others use the next formula:
middle = (low + high) / 2

I've done some test and both formulas yield to the same correct middle result.
My question is, do both always yield to the same result? or does any of them need to be used for specific scenarios or conditions?
If both are exactly the same, is there any reason why one would be used over the other?
 A: While the two formulas are equivalent mathematically, the first is preferred in computer programming, because of the possibility of overflow in the second.  Even though high and low are legitimate values, it is possible that high+low is too big.  Then the second formula will give an incorrect value, while the first would give the correct one.
A: Call them $m, l$ and $h$ for simplicity and we can see that $m= l+(h-l)/2 = l + h/2 -l/2=l/2 + h/2$ so both formulas are exactly the same.
A: $$a + \frac{b-a}{2} = \frac{2a}{2} + \frac{b-a}{2} = \frac{2a + b-a}{2} = \frac{b+a}{2}$$
A: Both those expression are mathematically equivalent. However, pay attention to floating-point arithmetics and its possible undesirable effects, such as the so-called  catastrophic cancellation.
For instance, if your are working with positive numbers, it is better to use the second expression. Indeed, when high and low are nearly equal, their subtraction can lead to an important reduction in the number of significant digits.
On the other hand, the sum high+low in the last formula may overcome the computational arithmetical limit of the used class of numbers.
