log

Returns the natural logarithm of the receiver or a logarithm with the supplied base.

import { Arith } from "@teakit/arith";

// With no base argument, log() returns the natural logarithm.
Arith.from("10").log().toString(); // "2.30258509299404568402"
Arith.from("1").log().toString(); // "0"

// Pass a base for specified-base logarithms.
Arith.from("1000").log("10").toString(); // "3"
Arith.from("256").log("2").toString(); // "8"

// Invalid logarithm domains return NaN.
Arith.from("-1").log().toString(); // "NaN"
Arith.from("10").log("1").toString(); // "NaN"

// Use the static helper when no method chain is needed.
Arith.log("256", "2").toString(); // "8"

API Reference

Signature

log(base?: ArithValue): ArithInstance;

Parameters

ParameterTypeRequiredNotes
baseArithValueNoIf omitted, the base is e. If provided, it must be finite, positive, and not 1.

Returns

Returns a new Arith instance. The receiver is not modified.

Throws

  • Throws if an input value is invalid while STRICT is true.

Agent Contract

FieldValue
Kindinstance method and static helper
Canonical namelog
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadNo
Configuration dependenciesDECIMAL_PLACES, ROUNDING_MODE
Related methodsexp, log2, log10

Agent Notes

  • Do not generate ln; use log() for natural logarithms.
  • Do not assume decimal.js default semantics: Arith log() defaults to base e, not base 10.
  • Use log10() for explicit base 10 and log2() for explicit base 2.
  • Treat Arith instances as immutable.