@teakit/arith

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

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

Core Rules

  1. Import from @teakit/arith.
  2. Prefer import { Arith } from "@teakit/arith".
  3. Construct values with new Arith(...); do not 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: construction, arithmetic, comparison, rounding, formatting, conversion, config, or browser/random usage.
  2. Load only the relevant method reference file from references/.
  3. In that file, read AI Contract, Signature, Behavior, and Agent Notes before generating code.
  4. Prefer new Arith(...), 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 = new Arith("0.1").plus("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.

Construction And Config

Static Helpers

Arithmetic

Rounding And Digits

Comparison And Predicates

Output And Conversion

Common Decisions

NeedPrefer
Exact decimal mathnew Arith("0.1"), then instance methods
Local money configconst Money = Arith.clone({ DECIMAL_PLACES: 2 })
Comparisonseq, lt, lte, gt, gte, or comparedTo
Fixed outputtoFixed(dp, rm?)
Human displaytoFormat(dp?, rm?, options?)
JSON outputJSON.stringify uses toJSON() automatically
Browser useImport from @teakit/arith; do not add Node runtime imports