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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jrc03c/complex-number

v0.0.6

Published

a little tool for performing simple operations with with complex numbers.

Readme

intro

a little tool for performing simple operations with with complex numbers.

installation

npm install @jrc03c/complex-number

usage

import { ComplexNumber } from "@jrc03c/complex-number"

// -----------------------------------------------------------------------------
// construct some complex numbers in various ways:

const a = new ComplexNumber()
a.print()
// 0 + 0i

const b = new ComplexNumber(2.3, -4.5)
b.print()
// 2.3 - 4.5i

const c = new ComplexNumber({ real: Math.random(), imag: Math.random() })
c.print()
// 0.302830970835392 + 0.8051186842022172i

const d = new ComplexNumber("0.1 + -0.2i")
d.print()
// 0.1 - 0.2i

const e = new ComplexNumber("-0.3 - 0.4i")
e.print()
// -0.3 - 0.4i

// -----------------------------------------------------------------------------
// add, subtract, multiply, and divide complex numbers:

b.add(c).print()
// 2.6028309708353916 - 3.6948813157977827i

c.sub(d).print()
// 0.202830970835392 + 1.0051186842022173i

d.mul(e).print()
// -0.11000000000000001 + 0.01999999999999999i

e.div(b).print()
// 0.043461237274862966 - 0.0888801879404855i

// -----------------------------------------------------------------------------
// get the conjugate of a complex number (i.e., a - bi) and the conjugate
// product (i.e., (a + bi) * (a - bi))

b.print()
// 2.3 - 4.5i
b.conj.print()
// 2.3 + 4.5i
b.conjProd.print()
// 25.54 + 0i

api

ComplexNumber() (constructor)

accepts as arguments any one of these:

  • null or undefined
  • a single real number
  • two numbers representing real and imaginary parts respectively
  • a string in the form a + bi
  • an options object with "real" and "imag" properties
  • a ComplexNumber instance
new ComplexNumber() // 0 + 0i
new ComplexNumber(5) // 5 + 0i
new ComplexNumber(2, 3) // 2 + 3i
new ComplexNumber("-0.009 - 0.0756i") // -0.009 - 0.0756i
new ComplexNumber({ real: -1.7, imag: 3.4 }) // -1.7 + 3.4i

properties

conj (getter)

returns a new ComplexNumber instance that represents the conjugate of the number (i.e., a - bi).

const x = new ComplexNumber("-2 - 3i")
x.print() // -2 - 3i
x.conj.print() // -2 + 3i

conjProd (getter)

returns a new ComplexNumber instance representing the product of the complex number and its conjugate (i.e., (a + bi) * (a - bi)). note that, by definition, the imaginary part of the returned value will always be zero (i.e., a + 0i).

const x = new ComplexNumber("-2 - 3i")
x.print() // -2 - 3i
x.conjProd.print() // 13 + 0i

imag

the imaginary part of the complex number as a floating point value.

real

the real part of the complex number as a floating point value.

methods

add()

returns a new ComplexNumber instance in which the number has been added to a given number. the arguments are the same as the constructor's.

const a = new ComplexNumber("2 + 3i")

a.add(4).print()
// 6 + 3i

a.add(5, -6).print()
// 7 - 3i

a.add("-7 + 8i").print()
// -5 + 11i

copy()

returns a new ComplexNumber instance with the same real and imaginary parts as the number.

const a = new ComplexNumber("2 + 3i")
a.print() // 2 + 3i
a.copy().print() // 2 + 3i

div()

returns a new ComplexNumber instance in which the number has been divided by a given number. the arguments are the same as the constructor's.

const a = new ComplexNumber("2 + 3i")

a.div(4).print()
// 0.5 + 0.75i

a.div(5, -6).print()
// -0.13114754098360656 + 0.4426229508196721i

a.div("-7 + 8i").print()
// 0.08849557522123894 - 0.3274336283185841i

mul()

returns a new ComplexNumber instance in which the number has been multiplied by a given number. the arguments are the same as the constructor's.

const a = new ComplexNumber("2 + 3i")

a.mul(4).print()
// 8 + 12i

a.mul(5, -6).print()
// 28 + 3i

a.mul("-7 + 8i").print()
// -38 - 5i

print()

logs to the console the value returned from the toString method.

const a = new ComplexNumber("2 + 3i")
a.print() // 2 + 3i

sub(v)

returns a new ComplexNumber instance in which a given number has been subtracted from the number. the arguments are the same as the constructor's.

const a = new ComplexNumber("2 + 3i")

a.sub(4).print()
// -2 + 3i

a.sub(5, -6).print()
// -3 + 9i

a.sub("-7 + 8i").print()
// 9 - 5i

toString()

returns the complex number as a string in the form a + bi.

const a = new ComplexNumber("2 + 3i")
console.log(a.toString()) // 2 + 3i