Complex information

in #ita18 days ago

export class ComplexNumber {
r : number;
i : number;

constructor(real: number, imaginary: number) {
this.r = real;
this.i = imaginary;
}

public get real(): number {
return this.r;
}

public get imag(): number {
return this.i;
}

public add(other: ComplexNumber): ComplexNumber {
return new ComplexNumber((this.r+other.r),(this.i+other.i));
}

public sub(other: ComplexNumber): ComplexNumber {
return new ComplexNumber((this.r-other.r),(this.i-other.i));
}

public mul(other: ComplexNumber): ComplexNumber {
return new ComplexNumber((this.rother.r-this.iother.i),(this.iother.r+this.rother.i));
}

public div(other: ComplexNumber): ComplexNumber {
return new ComplexNumber((this.rother.r+this.iother.i)/(other.rother.r+other.iother.i),(this.iother.r-this.rother.i)/(other.rother.r+other.iother.i));
}

public get abs(): number {
return Math.sqrt(this.ithis.i+this.rthis.r);
}

public get conj(): ComplexNumber {
return new ComplexNumber(this.real, this.imag ? this.imag * (-1) : 0);
}

public get exp(): ComplexNumber {
return new ComplexNumber(Math.exp(this.r)Math.cos(this.i), Math.exp(this.r)Math.sin(this.i));
}
}

Sort:  

You've got a free upvote from witness fuli.
Peace & Love!