API index

The package exports every item below as a named export. Its default export also contains the classes, parsing functions, type guards, and JSON reviver.

Classes

Export Constructor
Integer new Integer(value)
Rational new Rational(numerator, denominator?)
RationalInterval new RationalInterval(a, b)
CertifiedApproximation new CertifiedApproximation(candidate, enclosure, options?)
Fraction new Fraction(numerator, denominator?, options?)
FractionInterval new FractionInterval(a, b)
BaseSystem new BaseSystem(characters, name?, options?)
NumeralSystem new NumeralSystem({schema?, kind?, radix, tokens}) (since 0.6.0)
TypePromotion Static utility class; do not instantiate

NUMERAL_SYSTEM_SCHEMA and NUMERAL_LIMITS accompany NumeralSystem in the current checkout. These exports await a coordinated package release.

Parsing functions

Export Signature
parseNumber (value: string) => CoreNumber
parseCertifiedApproximation (value: string) => CertifiedApproximation
parseRational (value: string) => Rational
parseDecimal (value: string) => Rational
parseRepeatingDecimal (value: string) => Rational
parseMixedNumber (value: string) => Rational
parseContinuedFraction (value: string \| readonly (number \| bigint)[]) => Rational
parseInterval (value: string) => RationalInterval

TypeScript types

type IntegerInput = number | string | bigint | Integer;
type RationalInput = IntegerInput | Rational;
type CoreScalar = Integer | Rational;
type CoreNumber = CoreScalar | RationalInterval | CertifiedApproximation;
type SternBrocotDirection = "L" | "R";

Guards and JSON

isInteger, isRational, isRationalInterval, isCertifiedApproximation, isFraction, isFractionInterval, isBaseSystem, and isCoreNumber provide public runtime type checks. Use reviveCoreValue as a JSON.parse reviver for tagged output created by the core classes’ toJSON() methods.

The formatting result interfaces are:

interface RepeatingExpansion {
  decimal: string | null;
  period: number;
  truncated: boolean;
}

interface BaseExpansion {
  baseStr: string;
  period: number;
  limitHit: boolean;
}

interface DecimalMetadata {
  wholePart?: bigint;
  initialSegment: string;
  initialSegmentLeadingZeros?: number;
  initialSegmentRest?: string;
  periodDigits: string;
  periodLength: number;
  leadingZerosInPeriod?: number;
  periodDigitsRest?: string;
  isTerminating: boolean;
}

Method checklist

This is a compact inventory; the linked class pages document behavior, examples, edge cases, and return types.

Class Public members
Integer value; add, subtract, multiply, divide, modulo, negate, pow; comparisons; abs, sign, sign/parity predicates; gcd, lcm; toString, toBase, toNumber, toRational; E, factorial, doubleFactorial, bitLength; static zero, one, from, fromRational
Rational numerator, denominator; arithmetic, comparison, abs; fraction/mixed/decimal/base/scientific formatters; period metadata; continued fractions, convergents, and bounded approximations; E, bitLength; static construction helpers and formatting limits
RationalInterval start, end, isAscending, low, high; arithmetic, pow, mpow; containment/set operations; interval formatters; mediant, midpoint, shortestDecimal, denominatorInterval, randomRational, E, bitLength; static zero, one, unitInterval, point, fromString
CertifiedApproximation candidate, authoritative enclosure, immutable representation, sourceId, dependencies; scalar enclosure arithmetic; exact/interval conversions; possibleRelationsTo; copy, formatting, and JSON
Fraction numerator, denominator, isInfinite; unreduced arithmetic, comparisons, scale, reduce, E; mediant/Farey operations; Stern–Brocot navigation; static conversion and relationship helpers
FractionInterval low, high; mediantSplit, partitionWithMediants, partitionWith; conversion, string/equality, E; static fromRationalInterval
BaseSystem base, signed radix, digitOffset, fractional/quoting capability flags, characters, charMap, name; digit conversion/validation; equality/case behavior; presets, factories, and prefix registry
TypePromotion Type-level inspection/promotion; arithmetic dispatch; power, E notation, negation; syntactic type classification

The installed package’s index.d.ts is the authoritative machine-readable signature reference.