New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sigma-js/complexes

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sigma-js/complexes

Provides calculation functions related to complex numbers.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@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.


Keywords

FAQs

Package last updated on 05 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc