log2

Returns the base 2 logarithm of the receiver.

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

Arith.from("256").log2().toString(); // "8"
Arith.from("1").log2().toString(); // "0"
Arith.from("0.5").log2().toString(); // "-1"

// Non-power-of-two inputs are rounded by the constructor precision settings.
Arith.from("10").log2().toString(); // "3.32192809488736234787"

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

// Use the static helper when no method chain is needed.
Arith.log2("1024").toString(); // "10"

API Reference

Signature

log2(): ArithInstance;

Parameters

ParameterTypeRequiredNotes
None--This method does not take parameters.

Returns

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

Throws

  • Does not take user arguments; no argument validation is performed.

Agent Contract

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

Agent Notes

  • Prefer log2() over log(2) when base 2 is conceptually important.
  • Do not generate ln.
  • Treat Arith instances as immutable.