function [y, iters] = bisectsqrt(x, left, right)
% call: [y, iters] = bisectsqrt(x, left, right)
% bisection (binary search) to compute square root of x
% input: x (scalar), left (left end point), right (right end point)
% output: y, the approximate square root, and iters, number of iterations
iters = 1;
mid = (left + right)/2
while mid ~= left & mid ~= right
    iters = iters + 1;
    midsq = mid*mid;
    if midsq < x
        left = mid;
    else
        right = mid;
    end
    mid = (left + right)/2
end % while loop
y = mid
