class SquareRoot {

  public float calculateSquareRootIterative(int number) {
    //Search first candidate
    float candidate = 1f;
    while (candidate * candidate <= number) {
      candidate++;
    }
    candidate--;
    if (isGoodResultForSqrt(number, candidate * candidate)) {
      return candidate;
    }

    //Apply binary search.
    float top = candidate + 1;
    float bottom = candidate;
    float newCandidate = (top + bottom) / 2;
    float result = newCandidate * newCandidate;
    while (!isGoodResultForSqrt(number, result)) {
      if (result > number) {
        top -= 0.1f;
      } else {
        bottom -= 0.1f;
      }
      newCandidate = (top + bottom) / 2;
      result = newCandidate * newCandidate;
    }
    return Math.abs(newCandidate);
  }

}