config

Reads or updates the configuration for the current Arith constructor.

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

const previous = Arith.config();

// Update shared defaults for the default constructor.
Arith.config({ DECIMAL_PLACES: 5 });
Arith.from("1").div("3").toString(); // "0.33333"

// EXPONENTIAL_AT controls when toString switches notation.
Arith.config({ EXPONENTIAL_AT: 2 });
Arith.from("123").toString(); // "1.23e+2"
Arith.from("12.3").toString(); // "12.3"

// FORMAT controls toFormat defaults.
Arith.config({ FORMAT: { groupSeparator: " ", decimalSeparator: "," } });
Arith.from("1234.56").toFormat(); // "1 234,56"

// config() returns the current settings.
Arith.config().DECIMAL_PLACES; // 5

// Restore the previous config after temporary changes.
Arith.config(previous);

API Reference

Signature

Arith.config(object?: ArithConfig): ArithConfigResult;

Parameters

ParameterTypeRequiredNotes
objectArithConfigNoWhen omitted, the current configuration is returned. null and undefined leave config unchanged.

Returns

Returns the full current configuration after applying any supplied changes.

Throws

  • Throws if object is not an object.
  • Throws if a config value is outside its allowed range.
  • Throws if CRYPTO: true is requested and crypto is unavailable.

Configuration Fields

FieldDefaultNotes
DECIMAL_PLACES20Maximum decimal places for division, square root, negative powers, and base conversion.
ROUNDING_MODE4Default rounding mode, Arith.ROUND_HALF_UP.
EXPONENTIAL_AT[-7, 21]Controls when toString() uses exponential notation.
RANGE[-10000000, 10000000]Exponent bounds for underflow to zero and overflow to infinity.
CRYPTOfalseUse globalThis.crypto for random() when available.
STRICTtrueThrow on invalid values instead of returning NaN.
MODULO_MODE1Rounding rule used by mod().
POW_PRECISION0Optional significant-digit cap for pow().
FORMATgrouped decimal defaultsDefault output options for toFormat() and fromFormat().
ALPHABET0123456789abcdefghijklmnopqrstuvwxyzDigits used for base conversion.

Agent Contract

FieldValue
Kindstatic method
Canonical nameconfig
AliasesNone
Mutates receiverYes
ReturnsArithConfigResult
Accepts (string, base) overloadNo
Configuration dependenciesAll config fields
Related methodsclone

Agent Notes

  • Save the previous config before mutating shared Arith in examples or tests.
  • Prefer Arith.clone() for reusable code to avoid global config side effects.
  • Import with import { Arith } from "@teakit/arith"; default imports are unsupported.
  • Static helpers are called as Arith.method(...) and do not require an instance receiver.
  • Do not generate BigNumber, Decimal, isBigNumber, or isDecimal compatibility APIs.
  • Use string inputs for exact decimal values when a static helper accepts numeric values.