UNPKG

@nexys/math-ts

Version:

[![npm version](https://badge.fury.io/js/%40nexys%2Fmath-ts.svg)](https://www.npmjs.com/package/@nexys/math-ts) [![TavisCI](https://travis-ci.com/Nexysweb/tableau-wdc-react.svg?branch=master)](https://travis-ci.com/github/Nexysweb/math-ts) [![Deployment](

54 lines (53 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Complex { constructor(x, y = 0) { this.x = x; this.y = y; } static fromModAndPhase(mod, phase) { const x = Math.sin(phase) * mod; const y = Math.cos(phase) * mod; return new Complex(x, y); } multiply(c) { if (typeof c === 'number') { return this.multiply(new Complex(c)); } const x1 = c.x * this.x; const y1 = c.x * this.y; const y2 = c.y * this.x; const x2 = c.y * this.y; return new Complex(x1 - x2, y1 + y2); } sum(c) { if (typeof c === 'number') { return new Complex(this.x + c, this.y); } return new Complex(c.x + this.x, c.y + this.y); } modulus() { return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2)); } argument() { return Math.atan2(this.y, this.x); } conjugate() { return new Complex(this.x, -this.y); } pow(n) { const r = this.modulus(); const arg = this.argument(); const rn = Math.pow(r, n); const x = rn * Math.cos(n * arg); const y = rn * Math.sin(n * arg); return new Complex(x, y); } } exports.Complex = Complex; exports.exp = (theta) => { const x = Math.cos(theta); const y = Math.sin(theta); return new Complex(x, y); }; exports.default = Complex;