function mod
mod(
x: number,
y: number,
): number

Modulus after division.

Computes the modulus after division. This operation is element-wise for matrices and arrays.

Examples

Modulus of a vector with a scalar divisor

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], 2.2), [1.9999999999999991, -0.39999999999999947]);

Modulus of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], [5, 6]), [3, -1]);

Modulus of two matrices

import { assertEquals } from "jsr:@std/assert";

const a = [[5, 6, 5], [7, 8, -1]];
const b = [[-1, 3, -1], [4, 5, 9]];
assertEquals(mod(a, b), [[0, 0, 0], [3, 3, -1]]);

Parameters

x: number

The dividend

y: number

The divisor

Return Type

number

The modulus after division

Throws

If fewer than two arguments are provided

mod(
x: number,
y: array,
): array

Modulus after division.

Computes the modulus after division. This operation is element-wise for matrices and arrays.

Examples

Modulus of a vector with a scalar divisor

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], 2.2), [1.9999999999999991, -0.39999999999999947]);

Modulus of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], [5, 6]), [3, -1]);

Modulus of two matrices

import { assertEquals } from "jsr:@std/assert";

const a = [[5, 6, 5], [7, 8, -1]];
const b = [[-1, 3, -1], [4, 5, 9]];
assertEquals(mod(a, b), [[0, 0, 0], [3, 3, -1]]);

Parameters

x: number

The dividend

The divisor

Return Type

The modulus after division

Throws

If fewer than two arguments are provided

mod(
x: array,
y: number,
): array

Modulus after division.

Computes the modulus after division. This operation is element-wise for matrices and arrays.

Examples

Modulus of a vector with a scalar divisor

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], 2.2), [1.9999999999999991, -0.39999999999999947]);

Modulus of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], [5, 6]), [3, -1]);

Modulus of two matrices

import { assertEquals } from "jsr:@std/assert";

const a = [[5, 6, 5], [7, 8, -1]];
const b = [[-1, 3, -1], [4, 5, 9]];
assertEquals(mod(a, b), [[0, 0, 0], [3, 3, -1]]);

Parameters

The dividend

y: number

The divisor

Return Type

The modulus after division

Throws

If fewer than two arguments are provided

mod(
x: array,
y: array,
): array

Modulus after division.

Computes the modulus after division. This operation is element-wise for matrices and arrays.

Examples

Modulus of a vector with a scalar divisor

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], 2.2), [1.9999999999999991, -0.39999999999999947]);

Modulus of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], [5, 6]), [3, -1]);

Modulus of two matrices

import { assertEquals } from "jsr:@std/assert";

const a = [[5, 6, 5], [7, 8, -1]];
const b = [[-1, 3, -1], [4, 5, 9]];
assertEquals(mod(a, b), [[0, 0, 0], [3, 3, -1]]);

Parameters

The dividend

The divisor

Return Type

The modulus after division

Throws

If fewer than two arguments are provided

mod(
x: number,
y: matrix,
): matrix

Modulus after division.

Computes the modulus after division. This operation is element-wise for matrices and arrays.

Examples

Modulus of a vector with a scalar divisor

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], 2.2), [1.9999999999999991, -0.39999999999999947]);

Modulus of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], [5, 6]), [3, -1]);

Modulus of two matrices

import { assertEquals } from "jsr:@std/assert";

const a = [[5, 6, 5], [7, 8, -1]];
const b = [[-1, 3, -1], [4, 5, 9]];
assertEquals(mod(a, b), [[0, 0, 0], [3, 3, -1]]);

Parameters

x: number

The dividend

The divisor

Return Type

The modulus after division

Throws

If fewer than two arguments are provided

mod(
x: matrix,
y: number,
): matrix

Modulus after division.

Computes the modulus after division. This operation is element-wise for matrices and arrays.

Examples

Modulus of a vector with a scalar divisor

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], 2.2), [1.9999999999999991, -0.39999999999999947]);

Modulus of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], [5, 6]), [3, -1]);

Modulus of two matrices

import { assertEquals } from "jsr:@std/assert";

const a = [[5, 6, 5], [7, 8, -1]];
const b = [[-1, 3, -1], [4, 5, 9]];
assertEquals(mod(a, b), [[0, 0, 0], [3, 3, -1]]);

Parameters

The dividend

y: number

The divisor

Return Type

The modulus after division

Throws

If fewer than two arguments are provided

mod(
x: matrix,
y: matrix,
): matrix

Modulus after division.

Computes the modulus after division. This operation is element-wise for matrices and arrays.

Examples

Modulus of a vector with a scalar divisor

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], 2.2), [1.9999999999999991, -0.39999999999999947]);

Modulus of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(mod([13, -7], [5, 6]), [3, -1]);

Modulus of two matrices

import { assertEquals } from "jsr:@std/assert";

const a = [[5, 6, 5], [7, 8, -1]];
const b = [[-1, 3, -1], [4, 5, 9]];
assertEquals(mod(a, b), [[0, 0, 0], [3, 3, -1]]);

Parameters

The dividend

The divisor

Return Type

The modulus after division

Throws

If fewer than two arguments are provided