
Untitled
By: a guest on
Jul 31st, 2012 | syntax:
None | size: 0.62 KB | hits: 13 | expires: Never
public class Complex {
double re;
double im;
public Complex(double x0, double y0)
{
re = x0;
im = y0;
}
public double abs() { return Math.hypot(re, im); }
public Complex times(Complex b) {
Complex a = this;
double real = a.re * b.re - a.im * b.im;
double imag = a.re * b.im + a.im * b.re;
return new Complex(real, imag);
}
public Complex plus(Complex b) {
Complex a = this; // invoking object
double real = a.re + b.re;
double imag = a.im + b.im;
return new Complex(real, imag);
}
}