code: public double getSolution(double targetValue, double initGuess) {
      double rMax = 1.0;
      double oldValue = -1;
      for (int i = 0; i < MAXIMUM_ITERATION; ++i) {
        double value = targetFunction(rMax);
        if (value >= targetValue) {
          break;
        }
        if (equals(value, oldValue)) {
          return rMax; // Target value is not feasible. Just return rMax
        }
        rMax *= 2;
      }
      double left = 0;
      double right = rMax;
      double mid = initGuess > left && initGuess < right ?
          initGuess : (left + right) / 2.0;
      for (int i = 0; i < MAXIMUM_ITERATION; ++i) {
        double value = targetFunction(mid);
        if (equals(value, targetValue)) {
          return mid;
        }
        if (value < targetValue) {
          left = mid;
        } else {
          right = mid;
        }
        mid = (left + right) / 2.0;
      }
      return right;
    }
docs: Find the solution x for the target function f(x) such that
  f(x) == targetValue
  
  @param targetValue the value to solve against
  @param initGuess initial guess to take when performing binary search
  @return the solution (x)