Arith constructor

Creates an Arith value. This package requires the new keyword.

Summary

Use the constructor whenever you need a decimal value that should not be handled by JavaScript binary floating-point arithmetic. Prefer string literals for exact decimal input.

AI Contract

FieldValue
Kindconstructor
Canonical nameArith
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadYes
Configuration dependenciesSTRICT, RANGE, ALPHABET, DECIMAL_PLACES, ROUNDING_MODE
Related methodstoObject, isArith

Signature

new Arith(n: ArithValue): ArithInstance;
new Arith(n: string, base: number): ArithInstance;

Parameters

ParameterTypeRequiredNotes
nArithValueYesstring, number, bigint, ArithInstance, or an Arith instance-like object with _isArith: true.
basenumberNoOnly valid when n is a string. Must be an integer from 2 through ALPHABET.length.

Returns

Returns a new Arith instance representing the supplied value.

Behavior

  • new is required; calling Arith(...) throws an Arith Error.
  • String values can be decimal or exponential notation; prefixed binary, octal, and hexadecimal strings are accepted when valid.
  • When base is provided, n must be a string and is converted from that base into decimal form.
  • Base conversion is rounded according to DECIMAL_PLACES and ROUNDING_MODE.
  • Infinity, -Infinity, and NaN are supported values.
  • Plain objects are accepted only when they are tagged as Arith instance-like objects with _isArith: true.
  • When STRICT is false, invalid values become NaN; otherwise invalid values throw.

Examples

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

const exact = new Arith("0.1");
const fromHex = new Arith("ff", 16);

exact.plus("0.2").toString(); // "0.3"
fromHex.toString(); // "255"

Errors

  • Throws if called without new.
  • Throws if base is invalid.
  • Throws if n is invalid while STRICT is true.

Agent Notes

  • Generate new Arith(...), not Arith(...).
  • Do not generate BigNumber or Decimal constructor names for this package.
  • Import from @teakit/arith; prefer import { Arith } from "@teakit/arith".
  • Do not generate BigNumber, Decimal, isBigNumber, or isDecimal compatibility APIs.
  • Use string inputs for exact decimal values.

See Also