Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: cleanup #1

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: ci

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: read

jobs:
bun-test:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
bun: [canary]
os:
- ubuntu-22.04
- windows-2022
- macOS-12

steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: ${{ matrix.bun }}

- name: Install packages
run: bunx jsr add @cross/test @std/assert

- name: Run tests canary
run: bun test

deno-test:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
deno: [canary]
os:
- ubuntu-22.04
- windows-2022
- macOS-12

steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno }}

- name: Install packages
run: deno add @cross/test @std/assert

- name: Run tests
run: deno task test

node-test:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
node: [21.x]
os:
- ubuntu-22.04
- windows-2022
- macOS-12

steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Install packages
run: npx jsr add @cross/test @std/assert

- name: Add package.json
run: "echo '{ \"type\": \"module\" }' > package.json"

- name: Run tests canary
run: npx --yes tsx --test

lint:
runs-on: ubuntu-22.04
steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: canary

- name: Check linting
run: deno task lint
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ real part is `0`.

## `Complex` class

This package provides an implementation of complex numbers through `Complex`
This package provides an implementation of complex numbers through the `Complex`
class. It has methods to perform basic operations on complex numbers:

```ts
Expand All @@ -31,19 +31,19 @@ cmplx1.add(cmplx2); // (3 + i) + (2 + 9i) = (5 + 10i)
complx1.add(3); // (3 + i) + 3 = (3 + i) + (3 + 0i) = (6 + i)
```

Methods `conj()`, `abs()`, `phase()` return the conjuntion, absolute value, and
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.abs(); // 9.219544457292889 = Math.sqrt(85)
cmplx2.phase(); // 1.3521273809209546
```

## `ComplexMath`

Like `Math`, `ComplexMath` also provides some basic mathematics functionality
for complex numbers.
Like `Math`, `ComplexMath` also provides basic mathematics functionality for
complex numbers.

```ts
ComplexMath.sin(cmplxNumber);
Expand Down
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"indentWidth": 4
},
"imports": {
"@cross/test": "jsr:@cross/test@^0.0.9",
"@std/assert": "jsr:@std/assert@^0.225.3"
},
"exclude": [".vscode", "docs"],
"exclude": [".vscode", "docs", ".github"],
"tasks": {
"check": "deno publish --dry-run",
"lint": "deno fmt --check && deno lint",
Expand Down
4 changes: 2 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* A package provides implementation of complex numbers and mathematical functions
* for complex numbers.
* A package provides implementation of complex numbers and some mathematical
* functions for complex numbers.
*
* The `Complex` class represents a complex number which has a real part and an
* imaginary part. It is expressed in form `a + bi`, where:
Expand Down
54 changes: 39 additions & 15 deletions src/complex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export type complex = Complex;
* new Complex(14, 6); // 14 + 6i
*
* // A complex number can be also created from a real number
* Complex.fromRealNum(4); // 4 + 0i
* Complex.fromRealNum(32.9); // 32.9 + 0i
* Complex.fromReal(4); // 4 + 0i
* Complex.fromReal(32.9); // 32.9 + 0i
*
* // or a purely imaginary number
* Complex.fromImagNum(11); // 0 + 11i
* Complex.fromImagNum(6); // 0 + 6i
* Complex.fromImag(11); // 0 + 11i
* Complex.fromImag(6); // 0 + 6i
* ```
*/
export class Complex {
Expand Down Expand Up @@ -51,29 +51,61 @@ export class Complex {
* Creates a new complex number from a real number.
*
* @param real A real number
* @returns A new complex number
*
* @example
* ```ts
* Complex.fromReal(2); // 2 + 0i
* Complex.fromReal(0); // 0 + 0i
* ```
*/
static fromReal(real: number): Complex {
return new Complex(real);
}

/**
* Creates a new complex number from a purely imaginary number.
*
* @param imag A purely imaginary number
*
* @example
* ```ts
* Complex.fromImag(1); // 0 + i
* Complex.fromImag(10); // 0 + 10i
* ```
*/
static fromImag(imag: number): Complex {
return new Complex(0, imag);
}

/**
* Creates a new complex number from a real number.
*
* @param real A real
*
* @example
* ```ts
* Complex.fromRealNum(2); // 2 + 0i
* Complex.fromRealNum(0); // 0 + 0i
* ```
*
* @deprecated (will be removed after v1.0.1) Use {@linkcode fromReal} instead
*/
static fromRealNum(real: number): Complex {
return new Complex(real, 0);
return new Complex(real);
}

/**
* Creates a new complex number from a purely imaginary number.
*
* @param imag A purely imaginary number
* @returns A new complex number
*
* @example
* ```ts
* Complex.fromImagNum(1); // 0 + i
* Complex.fromImagNum(10); // 0 + 10i
* ```
*
* @deprecated (will be removed after v1.0.1) Use {@linkcode fromImag} instead
*/
static fromImagNum(imag: number): Complex {
return new Complex(0, imag);
Expand Down Expand Up @@ -172,7 +204,6 @@ export class Complex {
* Adds a real number to the complex number.
*
* @param other A real number.
* @returns The result of addition.
*
* @example
* ```ts
Expand All @@ -186,7 +217,6 @@ export class Complex {
* Adds two complex numbers.
*
* @param other The other complex number.
* @returns The result of addition.
*
* @example
* ```ts
Expand All @@ -212,7 +242,6 @@ export class Complex {
* Subtracts a real number from the complex number.
*
* @param other A real number.
* @returns The result of subtraction.
*
* @example
* ```ts
Expand All @@ -226,7 +255,6 @@ export class Complex {
* Subtracts two complex numbers.
*
* @param other The other complex number.
* @returns The result of subtraction.
*
* @example
* ```ts
Expand All @@ -252,7 +280,6 @@ export class Complex {
* Calculates the product of a real number and the complex number.
*
* @param other A real number.
* @returns The result of multiplication.
*
* @example
* ```ts
Expand All @@ -266,7 +293,6 @@ export class Complex {
* Calculates the product of two complex numbers.
*
* @param other The other complex number.
* @returns The result of multiplication.
*
* @example
* ```ts
Expand Down Expand Up @@ -297,7 +323,6 @@ export class Complex {
* Calculates the quotient of the complex number and a real number.
*
* @param other The other complex number.
* @returns The result of multiplication.
*
* @example
* ```ts
Expand All @@ -311,7 +336,6 @@ export class Complex {
* Calculates the quotient of two complex numbers.
*
* @param other The other complex number.
* @returns The result of division.
*
* @example
* ```ts
Expand Down
Loading