Skip to main content

Built and signed on GitHub Actions

A package provides implementation of complex numbers and mathematical functions for complex numbers.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
4 months ago (1.1.1)
class Complex

Represents a complex number which has a real part and an imaginary part.

Examples

Example 1

import { Complex } from "@babia/complex";

new Complex(1, 9);  // 1 + 9i
new Complex(14, 6); // 14 + 6i

// A complex number can be also created from a real number
Complex.fromReal(4);    // 4 + 0i
Complex.fromReal(32.9); // 32.9 + 0i

// or a purely imaginary number
Complex.fromImag(11); // 0 + 11i
Complex.fromImag(6);  // 0 + 6i

Constructors

new
Complex(
real?: number,
imag?: number,
)

Properties

The imaginary part of the complex number.

The real part of the complex number.

Methods

Returns the absolute value (or modulus or magnitude) of the complex number.

Adds a real number to the complex number.

Adds two complex numbers.

Returns the complex conjugate of the complex number.

Calculates the quotient of the complex number and a real number.

Calculates the quotient of two complex numbers.

Whether either the real part or imaginary part of the complex number is an infinity.

Whether either the real part or imaginary part of the complex number is NaN and neither is an infinity.

Whether the complex number is equal to 0.

Calculates the product of a real number and the complex number.

Calculates the product of two complex numbers.

Returns the phase (or argument) of the complex number.

Subtracts a real number from the complex number.

Subtracts two complex numbers.

Static Methods

Returns a complex number whose real part and imaginary part are both positive infinity.

Returns a complex number whose real part and imaginary part are NaN (not-a-number).

Creates a new complex number from a purely imaginary number.

Creates a new complex number from a real number.

Add Package

deno add jsr:@babia/complex

Import symbol

import { Complex } from "@babia/complex";

---- OR ----

Import directly with a jsr specifier

import { Complex } from "jsr:@babia/complex";

Add Package

npx jsr add @babia/complex

Import symbol

import { Complex } from "@babia/complex";

Add Package

yarn dlx jsr add @babia/complex

Import symbol

import { Complex } from "@babia/complex";

Add Package

pnpm dlx jsr add @babia/complex

Import symbol

import { Complex } from "@babia/complex";

Add Package

bunx jsr add @babia/complex

Import symbol

import { Complex } from "@babia/complex";