npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sigma-js/complexes

v1.0.0

Published

Provides calculation functions related to complex numbers.

Downloads

23

Readme

@sigma-js/complexes NPM version NPM license NPM monthly downloads NPM total downloads

@sigma-js/complexes is a JavaScript library that provides calculation functions related to complex numbers.

Install

Install with npm:

$ npm i @sigma-js/complexes

JavaScript require

const Complex = require("./complexes.js");

TypeScript import

import { Complex } from "@sigma-js/complexes";

Call example: constructor

// You can initialize complex numbers in the constructor
real = 1;
imaginary = 2;
complex = new Complex(real, imaginary);
console.log(complex.re); // Output: 1
console.log(complex.im); // Output: 2

Call example: rectCoords

// You can complex numbers can be set from rectangular coordinates.
complex = new Complex();
complex.rectCoords(3, 4);
console.log(complex.re); // Output: 3
console.log(complex.im); // Output: 4

Call example: polarCoords

// You can complex numbers can be set from polar coordinates.
complex = new Complex();
complex.polarCoords(1, Math.PI / 4);
console.log(complex.re); // Output: Math.sqrt(2) / 2
console.log(complex.im); // Output: Math.sqrt(2) / 2

Call example: precision

// You can set complex numbers with specified precision.
complex = new Complex();
complex.precision(1, Math.PI / 4);
console.log(complex.re); // Output: Math.sqrt(2) / 2
console.log(complex.im); // Output: Math.sqrt(2) / 2

Call example: fixed

// You can set complex numbers with specified digits.
complex = new Complex(3.141592653589793, 2.718281828459045);
complex.fixed(4);
console.log(complex.re); // Output: 3.1416
console.log(complex.im); // Output: 2.7183

Call example: fromValue

// You can get the complex number according to the specified value.
const inputComplex = new Complex(2, 4);
const beforeComplex = new Complex();
let retComplex = beforeComplex.fromValue(inputComplex);
retComplex.re; // Output: 2
retComplex.im; // Output: 4

retComplex = beforeComplex.fromValue("3+2i");
retComplex.re; // Output: 3
retComplex.im; // Output: 2

Call example: getMagnitude

// You can get the absolute value of a complex number.
const complex = new Complex(3, 4);
complex.getMagnitude(); // Output: 5

Call example: getAngle

// You can get the argument of a complex number.
  const complex = new Complex(3, 4);
complex.getAngle(); // Output: 0.92729...

Call example: conjugate

// You can get the conjugate value of a complex number.
const complex = new Complex(3, 4);
const conjugate = complex.conjugate();
conjugate.re; // Output: 3
conjugate.im; // Output: -4

Call example: negate

// You can get the negation of a complex number.
const complex = new Complex(3, 4);
const negate = complex.negate();
conjugate.re; // Output: -3
conjugate.im; // Output: -4

Call example: finalize

// You can modification of the current instance is prohibited and a new instance is always returned if one is needed.
const complex = new Complex(2, 3);
const finalizedComplex = complex.finalize();
const newComplex = finalizedComplex.rectCoords(4, 5);
console.log(newComplex); // Output: Complex { re: 4, im: 5 }

const reDescriptor = Object.getOwnPropertyDescriptor(finalizedComplex, "re");
const imDescriptor = Object.getOwnPropertyDescriptor(finalizedComplex, "im");
console.log(reDescriptor.writable); // Output: false
console.log(imDescriptor.writable); // Output: false

Call example: multiply

// You can set the result of multiplying the specified value by a complex number.
// When specified numerically
const beforeComplex = new Complex(2, 3);
const afterComplex = beforeComplex.multiply(3);
// (2 + 3i) * 3 = 6 + 9i
console.log(afterComplex.re); // Output: 6
console.log(afterComplex.im); // Output: 9

// When specified as a string
const beforeComplex = new Complex(2, 3);
const afterComplex = beforeComplex.multiply("2+4i");
// (2 + 3i) * (2 + 4i) = -8 + 14i
console.log(afterComplex.re); // Output: -8
console.log(afterComplex.im); // Output: 14

Call example: divide

// You can set the result of dividing the specified value by a complex number.
// When specified numerically
const beforeComplex = new Complex(6, 9);
const afterComplex = beforeComplex.divide(3);
// (6 + 9i) / 3 = 2 + 3i
console.log(afterComplex.re); // Output: 2
console.log(afterComplex.im); // Output: 3

// When specified as a string
const beforeComplex = new Complex(6, 9);
const afterComplex = beforeComplex.divide("2-4i");
// (6 + 9i) / (2 - 4i) = -1.2 + 2.1i
console.log(afterComplex.re); // Output: -2.1
console.log(afterComplex.im); // Output: 2.1

Call example: getClone

// You can get the clone of a complex number.
const complex = new Complex(2, 3);
const clone = complex.getClone();
console.log(clone.re); // Output: 2
console.log(clone.im); // Output: 3

Call example: exp

// You can get the result of exponentialing the specified value by a complex number.
const complex = new Complex(2, 3);
const expResult = complex.exp();
console.log(expResult.re); // Output: e^2 * cos(3)
console.log(expResult.im); // Output: e^2 * sin(3)

Call example: log

// You can set the logarithm of the specified rotation value to a complex number.
const complex = new Complex(2, 3);
const rotatedLog = complex.log(1);
console.log(rotatedLog.re); // Output: log(√13)
console.log(rotatedLog.im); // Output: 1.57079...

Call example: pow

// You can set the result of powing the specified value by a complex number.
const base = new Complex(2, 3);
const exponent = new Complex(1, 1);
const powResult = base.pow(exponent);
console.log(powResult.re); // Output: e^(2 - 3)
console.log(powResult.im); // Output: e^(2 - 3)

Call example: sqrt

// You can set the result of square rooting a complex number.
const complex = new Complex(2, 3);
const sqrtResult = complex.sqrt();
console.log(sqrtResult.re); // Output: √(√13 + 2) / 2
console.log(sqrtResult.im); // Output: √(√13 - 2) / 2
// You can get the hyperbolic sine of the specified value.
const complex = new Complex(2, 3);
const sinhResult = complex.getSinh(2);
console.log(sinhResult); // Output: 3.62686...

Call example: getCosh

// You can get the hyperbolic cosine of the specified value.
const complex = new Complex(2, 3);
const coshResult = complex.getCosh(2);
console.log(coshResult); // Output: 3.76219...
// You can set the sine of a complex number.
const re = 1, im = 2;
const complex = new Complex(re, im);
const sinResult = complex.sin();
console.log(sinResult.re); // 3.16577...
console.log(sinResult.im); // 1.95960...

Call example: cos

// You can set the cosine of a complex number.
const re = 2, im = 3;
const complex = new Complex(re, im);
const cosResult = complex.cos();
console.log(cosResult.re); // -4.18962...
console.log(cosResult.im); // -9.10922...

Call example: tan

// You can set the tangent of a complex number.
const re = 3, im = 4;
const complex = new Complex(re, im);
const tanResult = complex.tan();
console.log(tanResult.re); // -0.00018...
console.log(tanResult.im); // 0.99935...

Call example: sinh

// You can set the hyperbolic sine of a complex number.
const re = 1, im = 2;
const complex = new Complex(re, im);
const sinResult = complex.sinh();
console.log(sinResult.re); // -0.48905...
console.log(sinResult.im); // 1.40311...

Call example: cosh

// You can set the hyperbolic cosine of a complex number.
const re = 2, im = 3;
const complex = new Complex(re, im);
const cosResult = complex.cosh();
console.log(cosResult.re); // -3.72454...
console.log(cosResult.im); // 0.51182...

Call example: tanh

// You can set the hyperbolic tangent of a complex number.
const re = 3, im = 4;
const complex = new Complex(re, im);
const tanResult = complex.tanh();
console.log(tanResult.re); // 1.00070...
console.log(tanResult.im); // 0.00490...

Call example: getString

// You can get complex numbers as strings.
const complex = new Complex(3, -4);
const result = complex.getString();
console.log(result); // Output: 3-4i

Call example: getStringPolarCoords

// You can get a complex number as a string in polar coordinate format
const complex = new Complex(3, 4);
const result = complex.getStringPolarCoords();
console.log(result); // Output: 5 0.9272952180016122

Call example: getEquals

// You can obtain the result of determining whether the specified complex number and the current complex number match.
const complex1 = new Complex(2, 5);
const complex2 = new Complex(1, 5);
const result = complex1.getEquals(complex2);
console.log(result); // Output: false

License

Copyright (c) 2023, s-hama. Released under the MIT License.