set

set is an alias of config.

Summary

Use this for application-level defaults. For library code or isolated domains such as money math, use Arith.clone() and configure the clone instead.

AI Contract

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

Signature

Arith.set(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.

Behavior

  • Updates only fields present on the supplied object.
  • FORMAT is merged into the existing format object; omitted format fields keep their current values.
  • EXPONENTIAL_AT and RANGE accept either a single magnitude number or a [min, max] tuple.
  • CRYPTO: true requires an available globalThis.crypto implementation.
  • set and config are equivalent.

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 modulo().
POW_PRECISION0Optional significant-digit cap for exponentiatedBy().
FORMATgrouped decimal defaultsDefault output options for toFormat() and fromFormat().
ALPHABET0123456789abcdefghijklmnopqrstuvwxyzDigits used for base conversion.

Examples

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

const previous = Arith.set();

Arith.set({ DECIMAL_PLACES: 8, ROUNDING_MODE: Arith.ROUND_HALF_UP });
new Arith("1").div("3").toString(); // "0.33333333"

Arith.set(previous);

Errors

  • 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.

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 from @teakit/arith; prefer import { Arith } from "@teakit/arith".
  • 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.

See Also