function sqrt
sqrt(x: number): number

Computes the square root of a number, array, or matrix.

Computes the square root of each element in a number, array, or matrix. Returns NaN for negative values.

Examples

Square root of a single number

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

assertEquals(sqrt(6), 2.449489742783178);

Square root of an array of numbers

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

assertEquals(sqrt([5, 6, 3]), [2.23606797749979, 2.449489742783178, 1.7320508075688772]);

Square root of a matrix of numbers

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

assertEquals(sqrt([[5, 6, 5], [7, 8, 2]]), [[2.23606797749979, 2.449489742783178, 2.23606797749979], [2.6457513110645907, 2.8284271247461903, 1.4142135623730951]]);

Parameters

x: number

The input value(s)

Return Type

number

The square root of the input value(s)

Throws

If no arguments are provided

sqrt(x: array): array

Computes the square root of a number, array, or matrix.

Computes the square root of each element in a number, array, or matrix. Returns NaN for negative values.

Examples

Square root of a single number

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

assertEquals(sqrt(6), 2.449489742783178);

Square root of an array of numbers

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

assertEquals(sqrt([5, 6, 3]), [2.23606797749979, 2.449489742783178, 1.7320508075688772]);

Square root of a matrix of numbers

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

assertEquals(sqrt([[5, 6, 5], [7, 8, 2]]), [[2.23606797749979, 2.449489742783178, 2.23606797749979], [2.6457513110645907, 2.8284271247461903, 1.4142135623730951]]);

Parameters

The input value(s)

Return Type

The square root of the input value(s)

Throws

If no arguments are provided

sqrt(x: matrix): matrix

Computes the square root of a number, array, or matrix.

Computes the square root of each element in a number, array, or matrix. Returns NaN for negative values.

Examples

Square root of a single number

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

assertEquals(sqrt(6), 2.449489742783178);

Square root of an array of numbers

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

assertEquals(sqrt([5, 6, 3]), [2.23606797749979, 2.449489742783178, 1.7320508075688772]);

Square root of a matrix of numbers

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

assertEquals(sqrt([[5, 6, 5], [7, 8, 2]]), [[2.23606797749979, 2.449489742783178, 2.23606797749979], [2.6457513110645907, 2.8284271247461903, 1.4142135623730951]]);

Parameters

The input value(s)

Return Type

The square root of the input value(s)

Throws

If no arguments are provided

sqrt(x: number | array): number | array

Computes the square root of a number, array, or matrix.

Computes the square root of each element in a number, array, or matrix. Returns NaN for negative values.

Examples

Square root of a single number

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

assertEquals(sqrt(6), 2.449489742783178);

Square root of an array of numbers

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

assertEquals(sqrt([5, 6, 3]), [2.23606797749979, 2.449489742783178, 1.7320508075688772]);

Square root of a matrix of numbers

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

assertEquals(sqrt([[5, 6, 5], [7, 8, 2]]), [[2.23606797749979, 2.449489742783178, 2.23606797749979], [2.6457513110645907, 2.8284271247461903, 1.4142135623730951]]);

Parameters

x: number | array

The input value(s)

Return Type

number | array

The square root of the input value(s)

Throws

If no arguments are provided

sqrt(x: number | matrix): number | matrix

Computes the square root of a number, array, or matrix.

Computes the square root of each element in a number, array, or matrix. Returns NaN for negative values.

Examples

Square root of a single number

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

assertEquals(sqrt(6), 2.449489742783178);

Square root of an array of numbers

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

assertEquals(sqrt([5, 6, 3]), [2.23606797749979, 2.449489742783178, 1.7320508075688772]);

Square root of a matrix of numbers

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

assertEquals(sqrt([[5, 6, 5], [7, 8, 2]]), [[2.23606797749979, 2.449489742783178, 2.23606797749979], [2.6457513110645907, 2.8284271247461903, 1.4142135623730951]]);

Parameters

x: number | matrix

The input value(s)

Return Type

number | matrix

The square root of the input value(s)

Throws

If no arguments are provided

sqrt(x: array | matrix): array | matrix

Computes the square root of a number, array, or matrix.

Computes the square root of each element in a number, array, or matrix. Returns NaN for negative values.

Examples

Square root of a single number

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

assertEquals(sqrt(6), 2.449489742783178);

Square root of an array of numbers

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

assertEquals(sqrt([5, 6, 3]), [2.23606797749979, 2.449489742783178, 1.7320508075688772]);

Square root of a matrix of numbers

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

assertEquals(sqrt([[5, 6, 5], [7, 8, 2]]), [[2.23606797749979, 2.449489742783178, 2.23606797749979], [2.6457513110645907, 2.8284271247461903, 1.4142135623730951]]);

Parameters

The input value(s)

Return Type

The square root of the input value(s)

Throws

If no arguments are provided