function abs
abs(x: number): number

Absolute value.

Returns the absolute value of a number, or applies the absolute value function element-wise to arrays or matrices.

Examples

Compute the absolute value of a single number

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

assertEquals(abs(-0.5), 0.5);

Compute the absolute value of an array of numbers

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

assertEquals(abs([0.1, -0.5]), [0.1, 0.5]);

Compute the absolute value of a matrix

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

assertEquals(abs([[5, -2], [-3, 4]]), [[5, 2], [3, 4]]);

Parameters

x: number

The number, array, or matrix to compute the absolute value for

Return Type

number

The absolute value(s)

Throws

If no arguments are provided

abs(x: array): array

Absolute value.

Returns the absolute value of a number, or applies the absolute value function element-wise to arrays or matrices.

Examples

Compute the absolute value of a single number

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

assertEquals(abs(-0.5), 0.5);

Compute the absolute value of an array of numbers

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

assertEquals(abs([0.1, -0.5]), [0.1, 0.5]);

Compute the absolute value of a matrix

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

assertEquals(abs([[5, -2], [-3, 4]]), [[5, 2], [3, 4]]);

Parameters

The number, array, or matrix to compute the absolute value for

Return Type

The absolute value(s)

Throws

If no arguments are provided

abs(x: matrix): matrix

Absolute value.

Returns the absolute value of a number, or applies the absolute value function element-wise to arrays or matrices.

Examples

Compute the absolute value of a single number

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

assertEquals(abs(-0.5), 0.5);

Compute the absolute value of an array of numbers

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

assertEquals(abs([0.1, -0.5]), [0.1, 0.5]);

Compute the absolute value of a matrix

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

assertEquals(abs([[5, -2], [-3, 4]]), [[5, 2], [3, 4]]);

Parameters

The number, array, or matrix to compute the absolute value for

Return Type

The absolute value(s)

Throws

If no arguments are provided