imaginaryjs
v1.0.1
Published
A JavaScript library for complex number operations.
Maintainers
Readme
ImaginaryJS
A small JavaScript library for working with complex numbers in binomial and polar form.
Overview
ComplexNumber is a class that supports:
- creation from real and imaginary parts
- text conversion with
toString()anddisplay() - parsing complex numbers from strings
- arithmetic operations: addition, subtraction, multiplication, division
- advanced operations: square root, complex logarithm, polar conversion, powers, and complex trigonometry
Usage
import ComplexNumber from './imaginaryjs.js';
const z = new ComplexNumber([3, 4]);
console.log(z.toString()); // "3 + 4i"
const parsed = ComplexNumber.parser('5 - 2i');
console.log(parsed.real, parsed.imaginary);API
WIP
Constructor
new ComplexNumber([real = 0, imaginary = 0])
Creates a new complex number instance.
Instance methods
toString()- returns a formatted complex number stringdisplay()- alias fortoString()multiply(factors)- multiply this complex number by an array of other complex numbersaddition(numbers)- add an array of complex numbers to this onesubtract(numbers)- subtract an array of complex numbers from this onedivision(divisors)- divide this complex number by an array of divisorssqrt()- compute the principal square rootargument()- return the current argument in radians and degreesconjugate()- return the complex conjugatetoPolar()- convert this number to polar coordinateslogarithm(k = 0)- compute the complex logarithm with branchkpowInt(n = 2)- raise the number to an integer powerpowComplex(exponent)- raise the number to another complex exponentsin()- complex sinecos()- complex cosinetan()- complex tangent
Static methods
ComplexNumber.parser(string)- parse a complex number string into aComplexNumberComplexNumber.toBinomial({ modulus, theta })- convert polar coordinates back to binomial form
Error codes
0x7ECDAE3F- real part must be a number0x9E7DBCE1- imaginary part must be a number0xBADINPUT- invalid parser input0xDEADBEEF- division by zero
