public String toString() {
        if (Double.isNaN(im) || Double.isInfinite(im)) {
            return re + " + " + "i" + im;
        }
        if (im == 0) {
            return re + "";
        }
        if (re == 0) {
            return im + "i";
        }
        if (im < 0) {
            return re + " - " + (-im) + "i";
        }
        return re + " + " + im + "i";
    }