From b24e65c7a65f577b8797c0671133d7d1affe6993 Mon Sep 17 00:00:00 2001 From: Yasuhito Takamiya Date: Wed, 16 Aug 2023 11:57:32 +0900 Subject: [PATCH] =?UTF-8?q?tsdoc=20=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/common/src/complex.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/common/src/complex.ts b/packages/common/src/complex.ts index 3d79043bb..1b4ea7689 100644 --- a/packages/common/src/complex.ts +++ b/packages/common/src/complex.ts @@ -76,6 +76,9 @@ export class Complex { this.real = real this.imag = imag + // aliases for sub + this.subtract = this.sub + this.minus = this.sub // aliases for mult this.multiply = this.mult this.times = this.mult @@ -99,7 +102,7 @@ export class Complex { isApproximatelyEqualTo(other: number | Complex | unknown, epsilon: number): boolean { if (typeof other === 'number' || other instanceof Complex) { - const d = this.minus(Complex.from(other)) + const d = this.sub(Complex.from(other)) return Math.abs(d.real) <= epsilon && Math.abs(d.imag) <= epsilon && d.abs() <= epsilon } return false @@ -118,11 +121,20 @@ export class Complex { return new Complex(this.real + c.real, this.imag + c.imag) } - minus(value: number | Complex): Complex { + /** + * Returns the subtraction of this complex number and value. + * + * @param value - The subtrahend number. + * @returns A new complex number representing the subtraction of this complex number and value. + */ + sub(value: number | Complex): Complex { const c = Complex.from(value) return new Complex(this.real - c.real, this.imag - c.imag) } + subtract = this.sub.bind(this) + minus = this.sub.bind(this) + /** * Returns the product of this complex number and value. *