@teakit/arith

Use this skill when writing code for @teakit/arith.

@teakit/arith exports Arith, an arbitrary-precision decimal arithmetic API for ESM and browser environments.

Core Rules

  1. Import with import { Arith } from "@teakit/arith".
  2. Do not use default imports from @teakit/arith.
  3. Create values with Arith.from(...); do not use new Arith(...) or call Arith(...).
  4. Static methods such as Arith.config() and Arith.clone() are valid.
  5. Use string inputs for exact decimal values, especially money-like values.
  6. Do not generate BigNumber, Decimal, isBigNumber, or isDecimal.
  7. Do not use JavaScript arithmetic or comparison operators on Arith values.
  8. Use Arith.clone() when precision, rounding, or formatting config must stay local.
  9. Use toFixed() for fixed decimal places and toFormat() for display strings.
  10. Treat Arith instances as immutable. Do not mutate c, e, s, or _isArith.

Workflow

  1. Identify the operation: creation/configuration, core arithmetic, mathematical functions, rounding/precision/bounds, comparison, predicates, formatting/conversion, allocation, or static utilities.
  2. Load only the relevant method reference file from references/.
  3. In that file, read the intro, inline examples, API Reference, Agent Contract, and Agent Notes before generating code.
  4. Prefer Arith.from(...), exact string inputs, and Arith instance methods in generated code.
  5. If config is needed in reusable code, use a cloned constructor instead of shared Arith.config().
  6. For repository changes, run the local verification commands when relevant: bun run check, bun run typecheck, bun test, and bun run build.
  7. For documentation site changes, also run bun run docs:build.

Quick Example

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

const total = Arith.from("0.1").add("0.2");
total.toString(); // "0.3"

Reference Selection

Read the smallest method file that answers the current task. Do not load every reference file unless the user asks for a full API audit.

Creation & Configuration

Core Arithmetic

Mathematical Functions

Rounding, Precision & Bounds

Comparison

Predicates

Formatting & Conversion

Static Utilities

Common Decisions

NeedPrefer
Exact decimal mathArith.from("0.1"), then instance methods
Explicit ratiosArith.fromRatio("1/3") or Arith.ratio("1", "3")
Local money configconst Money = Arith.clone({ DECIMAL_PLACES: 2 })
Deterministic splitsArith.allocate(total, weights, options?)
Array statisticsArith.mean(values), Arith.quantile(values, q), or Arith.std(values)
Comparisonscmp, eq, ne, gt, ge, lt, or le
Fixed outputtoFixed(decimalPlaces, roundingMode?)
Human displaytoFormat(decimalPlaces?, roundingMode?, options?)
JSON outputJSON.stringify uses toJSON() automatically
Browser useImport from @teakit/arith; do not add Node runtime imports