BigInt
Unbounded integer values for handling extremely large numbers
Overview
The BigInt type in Internet Object represents arbitrary-precision integers that can handle numeric values exceeding the limitations of standard 64-bit number representations. This makes BigInt essential for applications that need to process extremely large whole numbers with perfect precision, such as cryptographic operations, large-scale counting, or mathematical computations requiring unbounded integer arithmetic.
Unlike the regular Number type, which is limited to safe integers within approximately ±9 quadrillion (±2^53-1), BigInt can represent integers of arbitrary length, ensuring that large numerical operations remain exact regardless of magnitude.
Representation and Syntax
A BigInt value in Internet Object is represented as an integer with the n
suffix:
Basic BigInt Literals
Alternative Numeric Bases
BigInt values can be expressed in different numeric bases:
Key Concepts
Arbitrary Precision
BigInt values are not subject to the precision limitations that affect standard floating-point numbers:
Integer-Only Operations
BigInt values represent whole numbers only and do not support fractional components:
Type Compatibility
BigInt is a distinct data type and cannot be implicitly mixed with regular numbers:
Schema Definition and Validation
When used with Internet Object schemas, BigInt types can be defined and validated:
The BigInt type supports these validation properties:
min/max: Validates value range
choices: Limits valid values to a predefined set
optional: Specifies if the field is optional
null: Determines if null values are allowed
Operations and Behavior
Arithmetic Operations
BigInt supports these arithmetic operations:
Bitwise Operations
BigInt supports standard bitwise operations:
Comparisons
BigInt values can be compared as expected:
Use Cases and Examples
BigInt types are particularly valuable in:
Cryptography - key generation, hash calculations
Large-scale counting - web analytics, statistics
Financial ledgers - tracking very large monetary amounts
Mathematical computations - number theory, combinatorial calculations
IDs and timestamps - high-precision time tracking, unique identifiers
Cryptographic Example
Analytics Counter Example
Best Practices
Use for Whole Numbers Only: BigInt is designed for integer operations and does not support fractional values.
Consider Performance Implications: BigInt operations may be slower than standard number operations, especially for very large values.
Explicit Type Conversions: When interfacing with systems that don't support BigInt, explicitly convert values to ensure compatibility.
Range Constraints: Even though BigInt can represent arbitrarily large values, consider setting practical min/max limits in schemas to prevent excessive resource usage.
Avoid Mixing with Regular Numbers: Maintain type consistency by not mixing BigInt with standard numbers in operations.
Technical Considerations
When implementing or working with BigInt values, keep these points in mind:
Memory Usage: BigInt values can consume significantly more memory than standard numbers, especially for very large values.
Serialization: When serializing to formats that don't natively support BigInt (like standard JSON), values must be represented as strings or custom formats.
Integer Division: Division with BigInt always produces integer results (truncated toward zero), which may require special handling for fractional calculations.
No Decimal Point: BigInt does not support decimal points or fractional values; for such needs, use the Number or Decimal types.
Implementation Model: Many BigInt implementations use a variable-length sequence of bits to represent integers of arbitrary size, providing theoretical support for numbers limited only by available memory.
Last updated
Was this helpful?