Suppose you want to run a bisection algorithm/binary search down to machine precision, which will always terminate in a few hundred steps due to exponential halving of the range of floats. For this to work, the following conditions should be satisfied: Let floats A<B and M = (A+B)/2. Then
A < M < B if and only if A and B are not neighboring floats.
A=M or M=B if and only if A and B are neighboring floats.
Is this always guaranteed in floating point arithmetic?
If not, is there any reasonable definition of a midpoint M for which these conditions hold? (Obviously, defining M as the upper neighbor of A would work, but that would not be a reasonable definition.)
Edit 1: As pointed out in the comments, the sum of A+B may overflow. I am not necessarily asking about this specific sequence of operations, something like M = A/2 + B/2 would also be valid, as well as other midpoint methods.
Edit 2: https://scicomp.stackexchange.com/questions/20369/robust-computation-of-the-mean-of-two-numbers-in-floating-point/20379 is related, for the weaker condition that min(A,B) <= M <= max(A,B), which works for M=A+(B/2−A/2) and also does not overflow. Another interesting approach for bisection is based on reinterpreting floats as integers: https://www.juliabloggers.com/bisecting-floating-point-numbers/