toBigInt

Converts the receiver to a bigint when finite and returns null for non-finite values.

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

Arith.from("123").toBigInt(); // 123n
Arith.from("9999999999999999999999999999999").toBigInt(); // 9999999999999999999999999999999n

// Non-integers are rounded before conversion.
Arith.from("1.5").toBigInt(); // 2n
Arith.from("1.5").toBigInt(Arith.ROUND_DOWN); // 1n

// Non-finite values cannot be represented as bigint.
Arith.from("Infinity").toBigInt(); // null
Arith.from("NaN").toBigInt(); // null

API Reference

Signature

toBigInt(roundingMode?: ArithRoundingMode): bigint | null;

Parameters

ParameterTypeRequiredNotes
roundingModeArithRoundingModeNoDefaults to current ROUNDING_MODE.

Returns

Returns a bigint when the receiver is finite; returns null for NaN and infinities.

Throws

  • Throws if roundingMode is invalid.

Agent Contract

FieldValue
Kindinstance method
Canonical nametoBigInt
AliasesNone
Mutates receiverNo
Returns`bigint
Accepts (string, base) overloadNo
Configuration dependenciesROUNDING_MODE
Related methodsintegerValue, toNumber

Agent Notes

  • Import with import { Arith } from "@teakit/arith"; default imports are unsupported.
  • Use Arith.from(...) to create values. Do not generate new Arith(...) or Arith(...).
  • Use string inputs for exact decimal values, especially money-like values.
  • Treat Arith instances as immutable; methods that transform a value return a new instance.
  • Do not mutate internal fields such as c, e, s, or _isArith.