Skip to content
Ubiquev1.0.4
functionlog
log(x: number): number

Computes the natural logarithm (base e).

Computes the natural logarithm (base e) for each element in a number, array, or matrix.

Examples

Natural logarithm of a single number

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

assertEquals(log(6), 1.791759469228055);

Natural logarithm of an array of numbers

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

const actual = log([5, 6, 3]);
const expected = [1.6094379124341003, 1.791759469228055, 1.0986122886681096];
assertEquals(actual.length, expected.length);
actual.forEach((v, i) => assertAlmostEquals(v, expected[i], 1e-12));

Natural logarithm of a matrix of numbers

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

const actual = log([[5, 6, 5], [7, 8, 2]]);
const expected = [
  [1.6094379124341003, 1.791759469228055, 1.6094379124341003],
  [1.9459101490553132, 2.0794415416798357, 0.6931471805599453]
];
assertEquals(actual.map(row => row.length), expected.map(row => row.length));
actual.forEach((row, i) => row.forEach((v, j) => assertAlmostEquals(v, expected[i][j], 1e-12)));

Parameters

x: number

The input value(s)

Return Type

number

The natural logarithm of the input value(s)

Throws

If no arguments are provided

log(x: array): array

Computes the natural logarithm (base e).

Computes the natural logarithm (base e) for each element in a number, array, or matrix.

Examples

Natural logarithm of a single number

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

assertEquals(log(6), 1.791759469228055);

Natural logarithm of an array of numbers

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

const actual = log([5, 6, 3]);
const expected = [1.6094379124341003, 1.791759469228055, 1.0986122886681096];
assertEquals(actual.length, expected.length);
actual.forEach((v, i) => assertAlmostEquals(v, expected[i], 1e-12));

Natural logarithm of a matrix of numbers

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

const actual = log([[5, 6, 5], [7, 8, 2]]);
const expected = [
  [1.6094379124341003, 1.791759469228055, 1.6094379124341003],
  [1.9459101490553132, 2.0794415416798357, 0.6931471805599453]
];
assertEquals(actual.map(row => row.length), expected.map(row => row.length));
actual.forEach((row, i) => row.forEach((v, j) => assertAlmostEquals(v, expected[i][j], 1e-12)));

Parameters

The input value(s)

Return Type

The natural logarithm of the input value(s)

Throws

If no arguments are provided

log(x: matrix): matrix

Computes the natural logarithm (base e).

Computes the natural logarithm (base e) for each element in a number, array, or matrix.

Examples

Natural logarithm of a single number

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

assertEquals(log(6), 1.791759469228055);

Natural logarithm of an array of numbers

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

const actual = log([5, 6, 3]);
const expected = [1.6094379124341003, 1.791759469228055, 1.0986122886681096];
assertEquals(actual.length, expected.length);
actual.forEach((v, i) => assertAlmostEquals(v, expected[i], 1e-12));

Natural logarithm of a matrix of numbers

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

const actual = log([[5, 6, 5], [7, 8, 2]]);
const expected = [
  [1.6094379124341003, 1.791759469228055, 1.6094379124341003],
  [1.9459101490553132, 2.0794415416798357, 0.6931471805599453]
];
assertEquals(actual.map(row => row.length), expected.map(row => row.length));
actual.forEach((row, i) => row.forEach((v, j) => assertAlmostEquals(v, expected[i][j], 1e-12)));

Parameters

The input value(s)

Return Type

The natural logarithm of the input value(s)

Throws

If no arguments are provided