Overview
JavaScript's native number type can only safely represent integers up to 2^53 (about 9 quadrillion). For larger numbers, Romasm uses BigInt support through the stdlib/bigint.js library.
Why Big Integers?
JavaScript Number Limits
- Maximum safe integer: 2^53 - 1 = 9,007,199,254,740,991
- Problem: Numbers larger than this lose precision
- Solution: Use BigInt for arbitrary-precision arithmetic
Use Cases
- Collatz Conjecture: Testing very large starting numbers
- Prime Searching: Finding large primes beyond JavaScript's limit
- Cryptography: Working with large keys and modular arithmetic
- Mathematical Research: Exploring unsolved problems with massive numbers
BigIntRomasm Class
The BigIntRomasm class provides arbitrary-precision operations:
Available Operations
add(a, b)- Additionsubtract(a, b)- Subtractionmultiply(a, b)- Multiplicationdivide(a, b)- Divisionmodulo(a, b)- Modulocompare(a, b)- ComparisonisEven(n)- Check if evenmultiply3Add1(n)- 3n+1 (for Collatz)divideBy2(n)- Divide by 2
Usage in Problem Explorers
BigInt support is automatically used in problem explorer pages like:
- Collatz Conjecture: Test starting numbers with hundreds of digits
- Twin Primes: Search for very large prime pairs
- Goldbach Conjecture: Verify even numbers beyond JavaScript's limit
Implementation Details
How It Works
BigInt values are stored as strings and operations are performed digit-by-digit, similar to how you'd do arithmetic by hand. This allows for numbers of arbitrary size, limited only by available memory.
Related Documentation
- Collatz Conjecture Explorer - Uses BigInt for large numbers
- Twin Primes Explorer - Prime searching with BigInt
- Basic Math Functions - Standard integer operations