Methods Summary |
---|
public Complex | add(Complex other)Add another Complex to this one
return add(this, other);
|
public static Complex | add(Complex c1, Complex c2)Add two Complexes
return new Complex(c1.r+c2.r, c1.i+c2.i);
|
public static Complex | divide(Complex c1, Complex c2)Divide c1 by c2.
return new Complex(
(c1.r*c2.r+c1.i*c2.i)/(c2.r*c2.r+c2.i*c2.i),
(c1.i*c2.r-c1.r*c2.i)/(c2.r*c2.r+c2.i*c2.i));
|
public boolean | equals(java.lang.Object o)
if (!(o instanceof Complex))
throw new IllegalArgumentException(
"Complex.equals argument must be a Complex");
Complex other = (Complex)o;
return r == other.r && i == other.i;
|
public double | getImaginary()Return just the Real part
return i;
|
public double | getReal()Return just the Real part
return r;
|
public int | hashCode()
return (int)( r) | (int)i;
|
public double | magnitude()Return the magnitude of a complex number
return Math.sqrt(r*r + i*i);
|
public Complex | multiply(Complex other)Multiply this Complex times another one
return multiply(this, other);
|
public static Complex | multiply(Complex c1, Complex c2)Multiply two Complexes
return new Complex(c1.r*c2.r - c1.i*c2.i, c1.r*c2.i + c1.i*c2.r);
|
public Complex | subtract(Complex other)Subtract another Complex from this one
return subtract(this, other);
|
public static Complex | subtract(Complex c1, Complex c2)Subtract two Complexes
return new Complex(c1.r-c2.r, c1.i-c2.i);
|
public java.lang.String | toString()Display the current Complex as a String, for use in
println() and elsewhere.
StringBuffer sb = new StringBuffer().append(r);
if (i>0)
sb.append('+"); // else append(i) appends - sign
return sb.append(i).append('i").toString();
|