Combining IF and SIGN functions in Excel

Try this formula for A starting in the third iteration (row 4):

=IF(SIGN($D3)=SIGN($D2),IF(A3=A2,A3,$B3),IF(A3=A2,$B3,A3))

You can apply the same to C as well.

=IF(SIGN($D3)=SIGN($D2),IF(C3=C2,C3,$B3),IF(C3=C2,$B3,C3))

This uses two levels of conditions; first it checks for sign change in f(m), and then checks whether the midpoint was previously being mapped to the lower or upper bound.

Sample output:

enter image description here