Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/babiabeo/complex
A package provides implementation of complex numbers and mathematical functions for complex numbers.
https://github.com/babiabeo/complex
complex-numbers jsr mathematics
Last synced: 24 days ago
JSON representation
A package provides implementation of complex numbers and mathematical functions for complex numbers.
- Host: GitHub
- URL: https://github.com/babiabeo/complex
- Owner: babiabeo
- License: mit
- Created: 2024-06-03T16:11:44.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-11T14:14:14.000Z (8 months ago)
- Last Synced: 2024-11-10T07:07:56.144Z (3 months ago)
- Topics: complex-numbers, jsr, mathematics
- Language: TypeScript
- Homepage: https://jsr.io/@babia/complex
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# complex
[![JSR](https://jsr.io/badges/@babia/complex)](https://jsr.io/@babia/complex)
[![CI](https://github.com/babiabeo/complex/actions/workflows/ci.yml/badge.svg)](https://github.com/babiabeo/complex/actions/workflows/ci.yml)A package provides implementation of complex numbers and mathematical functions
for complex numbers.## What is a complex number?
A complex number is an extension of the real numbers. It combines both real and
imaginary components. It can be expressed in form `a + bi`, where:- `a`: the real part
- `b`: the imaginary part
- `i`: the imaginary unitA real number can be regarded as a complex number `a + 0i`, whose the imaginary
part is `0`. A purely imaginary number is a complex number `0 + bi`, whose the
real part is `0`.## `Complex` class
This package provides an implementation of complex numbers through the `Complex`
class. It has methods to perform basic operations on complex numbers:```ts
const cmplx1 = new Complex(3, 1); // 3 + i
const cmplx2 = new Complex(2, 9); // 2 + 9icmplx1.add(cmplx2); // (3 + i) + (2 + 9i) = (5 + 10i)
// Also works with real numbers
cmplx1.add(3); // (3 + i) + 3 = (3 + i) + (3 + 0i) = (6 + i)
```Methods `conj()`, `abs()`, `phase()` return the conjugate, absolute value, and
argument of the complex number respectively:```ts
cmplx2.conj(); // (2 - 9i)
cmplx2.abs(); // ≈ 9.219544457292889 = Math.sqrt(85)
cmplx2.phase(); // 1.3521273809209546
```## `cmplx` function
For convenience, the `cmplx` function was added in `v1.1.0` to help create
complex numbers more easily.```ts
cmplx(2, 3); // 2 + 3i
```Unlike the `Complex` class, the `cmplx` function requires the first argument
(the real part).```ts
cmplx(0); // 0 + 0i
```## `ComplexMath`
Like [`Math`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math), `ComplexMath` provides basic mathematics functionality for
complex numbers.- Exponential and logarithm functions
```ts
ComplexMath.exp();
ComplexMath.log();
// ...
```- Hyperbolic functions:
```ts
ComplexMath.sinh();
ComplexMath.atanh();
// ...
```- Power functions:
```ts
ComplexMath.sqrt();
ComplexMath.pow();
// ...
```- Trigonometric functions:
```ts
ComplexMath.asin();
ComplexMath.tan();
// ...
```## Related
- Go [`math/cmplx`](https://pkg.go.dev/math/cmplx)
- C++ [`std::complex`](https://en.cppreference.com/w/cpp/numeric/complex)
- Python [`complex`](https://docs.python.org/3/library/functions.html#complex)
and [`cmath`](https://docs.python.org/3/library/cmath.html)## License
MIT