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

pro-complex-math

v1.0.4

Published

A professional package for complex number operations and advanced mathematical functions

Readme

pro-complex-math

npm | License | Tests

A powerful, optimized, and TypeScript-based package for complex number operations and advanced mathematical functions. Whether you’re handling intricate calculations or financial computations, this package is built for developers who need precise outcomes with a dash of fun.

Features

  • Complex Number Operations: Addition, subtraction, multiplication, division, and more.
  • Financial Tools: Simple interest, compound interest, and NPV calculations.
  • Advanced Math: Exponentiation, logarithms, and sine for complex numbers.
  • TypeScript Ready: Full IntelliSense support for autocompletion and documentation.
  • Robust Error Handling: Clear and witty error messages for edge cases.

Installation

Install the package with a single command:

npm install pro-complex-math

And you’re set to conquer the world of math!

Usage

Here’s how to use every feature, with examples and details to make it crystal clear.

Complex Number Operations

The Complex class is your key to mastering complex numbers.

new Complex(real, imag)

Creates a new complex number with real and imaginary parts.

  • real (number): The real part.
  • imag (number): The imaginary part.
const { Complex } = require("pro-complex-math");
const c = new Complex(1, 2); // 1 + 2i
console.log(c.toString()); // "1 + 2i"

add(other)

Adds two complex numbers together.

  • other (Complex): The number to add.
const c1 = new Complex(1, 2);
const c2 = new Complex(3, 4);
const sum = c1.add(c2);
console.log(sum.toString()); // "4 + 6i"

subtract(other)

Subtracts one complex number from another.

  • other (Complex): The number to subtract.
const c1 = new Complex(5, 6);
const c2 = new Complex(3, 4);
const diff = c1.subtract(c2);
console.log(diff.toString()); // "2 + 2i"

multiply(other)

Multiplies two complex numbers.

  • other (Complex): The number to multiply with.
const c1 = new Complex(1, 2);
const c2 = new Complex(3, 4);
const product = c1.multiply(c2);
console.log(product.toString()); // "-5 + 10i"

divide(other)

Divides one complex number by another.

  • other (Complex): The divisor.

Throws: "Division by zero? Not cool!" if dividing by 0 + 0i.

const c1 = new Complex(1, 2);
const c2 = new Complex(1, 1);
const quotient = c1.divide(c2);
console.log(quotient.toString()); // "1.5 + 0.5i"

conjugate()

Returns the complex conjugate (flips the imaginary part).

const c = new Complex(1, 2);
const conj = c.conjugate();
console.log(conj.toString()); // "1 + -2i"

magnitude()

Calculates the magnitude (absolute value) of the complex number.

const c = new Complex(3, 4);
console.log(c.magnitude()); // 5 (sqrt(3² + 4²))

phase()

Gets the phase (argument) in radians.

const c = new Complex(1, 1);
console.log(c.phase()); // ~0.785 (π/4 radians)

toPolar()

Converts to polar form (magnitude and phase).

const c = new Complex(3, 4);
const polar = c.toPolar();
console.log(polar); // { magnitude: 5, phase: ~0.927 }

Complex.fromPolar(magnitude, phase)

Creates a complex number from polar coordinates.

  • magnitude (number): The magnitude.
  • phase (number): The phase in radians.
const c = Complex.fromPolar(5, Math.PI / 4);
console.log(c.toString()); // "~3.536 + 3.536i"

toString()

Returns a clean string representation.

const c = new Complex(1, -2);
console.log(c.toString()); // "1 + -2i"

Financial & Advanced Math Functions

simpleInterest(principal, rate, time)

Calculates simple interest—straightforward and sweet!

  • principal (number): Initial amount.
  • rate (number): Interest rate per period.
  • time (number): Number of periods.

Throws: "No negatives allowed, fam!" if any input is negative.

const { simpleInterest } = require("pro-complex-math");
console.log(simpleInterest(1000, 0.05, 2)); // 1100

compoundInterest(principal, rate, time, n)

Computes compound interest—watch your money grow!

  • principal (number): Initial amount.
  • rate (number): Interest rate per period.
  • time (number): Number of periods.
  • n (number, optional): Compounding frequency (default: 1).

Throws: "Invalid input, dude!" if inputs are negative or n is zero/negative.

const { compoundInterest } = require("pro-complex-math");
console.log(compoundInterest(1000, 0.05, 2)); // ~1102.5
console.log(compoundInterest(1000, 0.05, 2, 2)); // ~1103.8 (semi-annual)

npv(rate, cashFlows)

Calculates Net Present Value—how much is your money worth today?

  • rate (number): Discount rate.
  • cashFlows (number[]): Array of cash flows (negative for outflows).

Throws: "Discount rate can’t be ≤ -1, bro!" if rate is too low.

const { npv } = require("pro-complex-math");
const cashFlows = [-1000, 300, 400, 500];
console.log(npv(0.1, cashFlows)); // ~62.09

exp(z)

Computes the exponential of a complex number (e^z).

  • z (Complex): The complex input.
const { exp, Complex } = require("pro-complex-math");
const result = exp(new Complex(0, Math.PI));
console.log(result.toString()); // "-1 + 0i" (e^(iπ) = -1)

log(z)

Calculates the natural logarithm of a complex number.

  • z (Complex): The complex input.

Throws: "Log of zero? Nope!" if z is 0 + 0i.

const { log, Complex } = require("pro-complex-math");
const result = log(new Complex(1, 1));
console.log(result.toString()); // "~0.346 + 0.785i"

sin(z)

Computes the sine of a complex number.

  • z (Complex): The complex input.
const { sin, Complex } = require("pro-complex-math");
const result = sin(new Complex(Math.PI / 2, 0));
console.log(result.toString()); // "1 + 0i"

Requirements

  • Node.js: v14 or higher.
  • TypeScript: Optional, for IntelliSense goodness.

Development

Want to contribute or tweak it? Here’s how:

Clone the repo:

git clone https://github.com/yourusername/pro-complex-math.git

Install dependencies:

npm install

Build the package:

npm run build

Run the tests:

npm test

License

MIT License—check out the LICENSE file for details.

Author

Built by Dev - @debrajrout28 Got ideas or need help? Hit me up—I’m always down to chat code!