Question 7. Approximation algorithms [ 10 marks ]

Could the function below go into an infinite loop for some values of x?
Justify your answer.

    // display the square root of x
    void displaySquareRoot(float x)
    {
       float lower, upper;
       if (x < 0) {
          displaySquareRoot(-x);
          cout << "i";
       } else {
          if (x < 1) {
            lower = 0;
            upper = 1;
          } else {
            lower = 1;
            upper = x;
          } 
          do {
             float middle = (lower + upper) / 2;
             float square = middle * middle;
             if (square == x) {
                lower = middle;
                upper = middle;
                cout << middle;
             } else if (square < x) {
                lower = middle;
             } else {
                upper = middle;
             }
          } while (lower < upper);
       }
    }