https://github.com/kailuser/complex-math-js
NumJs is a npm/bower package for scientific computing with JavaScript. It contains among other things:
https://github.com/kailuser/complex-math-js
Last synced: 8 months ago
JSON representation
NumJs is a npm/bower package for scientific computing with JavaScript. It contains among other things:
- Host: GitHub
- URL: https://github.com/kailuser/complex-math-js
- Owner: KailUser
- License: mit
- Created: 2023-02-19T13:08:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-19T17:13:27.000Z (over 3 years ago)
- Last Synced: 2025-02-26T10:41:58.238Z (over 1 year ago)
- Language: JavaScript
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Complex Math JS



[](https://www.jsdelivr.com/package/npm/complex-math-js)
[](https://complex-math-js.readthedocs.io/en/latest/?badge=latest)
A lightweight JavaScript library for complex number arithmetic.
## Installation
You can install `complex-math-js` using npm:
```npm
npm install complex-math-js
```
## Usage
```js
const { Complex, addComplexNumbers, subtractComplexNumbers, multiplyComplexNumbers, divideComplexNumbers } = require('complex-math-js');
const a = new Complex(1, 2);
const b = new Complex(3, 4);
console.log(a.add(b)); // Output: 4 + 6i
console.log(a.subtract(b)); // Output: -2 - 2i
console.log(a.multiply(b)); // Output: -5 + 10i
console.log(a.divide(b)); // Output: 0.44 + 0.08i
console.log(a.magnitude()); // Output: 2.23606797749979
console.log(a.conjugate()); // Output: 1 - 2i
```
### On site
```html
import complex-math-js from https://cdn.jsdelivr.net/npm/complex-math-js/+esm
```
## API
Complex
A class representing a complex number.
## Constructor:
`new Complex(real, imag)`: Creates a new complex number object with the given real and imaginary components.
## Methods:
`add(other)`: Returns a new Complex object that is the sum of this complex number and the other complex number.
`subtract(other)`: Returns a new Complex object that is the difference between this complex number and the other complex number.
`multiply(other)`: Returns a new Complex object that is the product of this complex number and the other complex number.
`divide(other)`: Returns a new Complex object that is the quotient of this complex number and the other complex number.
`magnitude()`: Returns the magnitude (absolute value) of this complex number.
`conjugate()`: Returns a new Complex object that is the complex conjugate of this complex number.
`toString()`: Returns a string representation of this complex number.
## Functions
`addComplexNumbers(a, b)`: Returns the sum of the a and b complex numbers.
`subtractComplexNumbers(a, b)`: Returns the difference between the a and b complex numbers.
`multiplyComplexNumbers(a, b)`: Returns the product of the a and b complex numbers.
`divideComplexNumbers(a, b)`: Returns the quotient of the a and b complex numbers.
## License
