General bisection algorithm for functions (double -> T)