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

@iamsquare/complex.js

v1.0.4

Published

A simple complex numbers library written in Typescript

Downloads

16

Readme

Logo

ℂomplex.js

NPM Travis (.org) branch GitHub issues GitHub License NPM

A simple complex-numbers library for browsers and Node.js.

This library was created as solution for this RosettaCode task. It has been moved to its own repo as a way to learn TDD with Travis-CI.

Getting started

Complex.js can be used in both the browser and Node.js:

Install complex.js using npm:

npm i @iamsquare/complex.js

Since this library is compiled from Typescript, type definition files are provided by default. No additional @types installation required!

Building

Just clone this repo and build the library:

git clone --depth=0 https://github.com/iamsquare/complex.js
cd complex.js/
npm i
npm run prod

npm run prod will run Jest and build the library only if it passes all tests. To build without testing:

npm run build

Polyfills are not included (read Usage to learn more).

Usage

Just import the Complex class and the operations/functions you want to use in your Javascript (ES5/ES6/ES7) or Typescript project:

ES6/ES7/Typescript

import { Complex, add, log, pow, asinh, ...} from '@iamsquare/complex.js';

ES5

var ComplexJS = require('@iamsquare/complex.js');
var Complex = ComplexJS.Complex; // This line assigns the Complex constructor to the Complex variable.
var add = ComplexJS.add; // This line assigns the add operation to the add variable.
...

Note: for ES5 you will need to polyfill the following methods and properties when necessary:

  • core-js/modules/es6.math.sinh
  • core-js/modules/es6.math.cosh
  • core-js/modules/es6.math.tanh
  • core-js/modules/es6.math.hypot
  • core-js/modules/es6.math.sign
  • core-js/modules/es6.number.epsilon
  • core-js/modules/es6.number.is-nan
  • core-js/modules/es6.number.is-finite
  • core-js/modules/es6.number.is-integer

To keep the build as little as possible - and to let old tech die - these polyfills are NOT included in the bundle. You almost surely use Babel in your workflow anyway, so it's useless to polyfill the library beforehand (you can find a guide on how to include built-ins here).

Documentation

The library documentation can be found here.

Examples

Declaration

const z: Complex = new Complex(1, -1); // Numeric arguments
const w: Complex = new Complex({ x: 1, y: -3 }); // Cartesian argument
const k: Complex = new Complex({ r: 1, p: Math.PI / 2 }); // Polar argument
const zz: Complex = new Complex(z); // Complex argument

Addition

const a: Complex = add(z, w);
console.log(a); // => Complex {re: 2, im: -4}

Subtraction

const s: Complex = subtract(z, w);
console.log(s); // => Complex {re: 0, im: 2}

Multiplication

const m: Complex = multiply(z, w);
console.log(m); // => Complex {re: -2, im: -4}

Division

const d: Complex = divide(z, w);
console.log(d); // => Complex {re: 0.39999999999999997, im: 0.2}

These are just the four basic operations. Check the documentation to know more.

TODO

  • [x] ~~Support for trig functions.~~
  • [x] ~~Support for hyperbolic functions.~~
  • [x] ~~Support for powers.~~
  • [ ] Support for nth-roots (n√z).
  • [ ] Refactor tests.
  • [x] ~~Refactor the Complex class.~~

Built With

Licensing

The code in this project is licensed under MIT License.