DigitHelm
Number Theory

Big Number Calculator | Arbitrary Precision Arithmetic

Perform exact arithmetic on integers of any size using JavaScript BigInt. Supports addition, subtraction, multiplication, exponentiation, factorial, GCD, LCM, and modular arithmetic with no floating-point rounding errors. Displays the number of digits in the result and checks whether the result is prime using the Miller-Rabin primality test.

Instant Results100% FreeAny DeviceNo Sign-up

Exact addition

What Is the Big Number Calculator | Arbitrary Precision Arithmetic?

JavaScript's native BigInt type enables exact integer arithmetic on numbers of any size, with no floating-point rounding. Standard Number is limited to ~15 significant digits; BigInt has no such limit. This calculator supports addition, subtraction, multiplication, exponentiation (B ≤ 10,000), GCD and LCM via the Euclidean algorithm, modular arithmetic (always non-negative), modular exponentiation via fast binary method, exact factorial (A ≤ 1,000), and integer square root via Newton's method. Results show digit count, sign, and a deterministic Miller-Rabin primality test correct up to 3.3 × 10²⁴.

Formula

Arbitrary-precision integer arithmetic using JavaScript BigInt — exact results for any digit count

How to Use

  1. 1

    Click an operation button to select what to compute (Add, Power, GCD, etc.)

  2. 2

    Enter Number A — digits, optional leading minus sign; commas and underscores are stripped

  3. 3

    Enter Number B for binary operations (and Number C for Aᴮ mod C)

  4. 4

    Click "Calculate" to get the exact result

  5. 5

    Use the Copy button to copy large results to your clipboard

  6. 6

    Expand Steps to see the Euclidean algorithm for GCD or the verification for integer square root

Select an operation, enter numbers A, B (and C for modular exponentiation), then click Calculate for an exact result.

Example Calculation

100! (100 factorial) equals a 158-digit number, computed instantly with zero rounding error:

93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

To reproduce: enter 100 in field A, select Factorial A!, and click Calculate.

Understanding Big Number | Arbitrary Precision Arithmetic

Available Operations

OperationSymbolInputsLimitsNotes
AddA + BA, BUnlimitedExact carry-propagation, any digit count
SubtractA − BA, BUnlimitedExact, result may be negative
MultiplyA × BA, BUnlimitedExact; uses JavaScript BigInt multiplication
PowerAᴮA, BB ≤ 10,000Result can have thousands of digits
GCDgcd(A,B)A, BUnlimitedEuclidean algorithm with step-by-step output
LCMlcm(A,B)A, BUnlimited= |A|·|B| / gcd(A,B)
ModA mod BA, BB > 0Always in [0, B−1], even for negative A
Mod PowerAᴮ mod CA, B, CB ≥ 0, C > 0Fast binary exponentiation — no size limit on B
FactorialA!AA ≤ 1,0001000! has 2,568 digits
Integer √⌊√A⌋AA ≥ 0Newton's method, verified: r²≤A<(r+1)²

Notable Large Factorials

nn! digit countTrailing zerosPrime check
10!72No (ends in 0)
20!194No
50!6512No
100!15824No
500!1,135124No
1000!2,568249No

Why Standard Floating-Point Fails for Large Numbers

  • JavaScript's Number type uses 64-bit IEEE 754 double precision — only 53 bits of mantissa, giving ~15-16 significant decimal digits.
  • Any integer larger than Number.MAX_SAFE_INTEGER (9,007,199,254,740,991 ≈ 9×10¹⁵) loses precision.
  • Example: in a standard calculator, 9007199254740992 + 1 = 9007199254740992 (wrong). BigInt gives the correct 9007199254740993.
  • Modular exponentiation (Aᴮ mod C) is impossible with floating-point for large B because the intermediate Aᴮ overflows to Infinity.
  • BigInt stores integers as arbitrary-length binary arrays, so every operation is exact regardless of how many digits the result has.

Frequently Asked Questions

What is the largest number this can handle?

There is no practical limit on input size. Exponentiation is capped at B ≤ 10,000 and factorial at A ≤ 1,000 to avoid browser freezing, but addition, subtraction, multiplication, GCD, LCM, and mod work on numbers of any digit count.

How does the GCD algorithm work?

The Euclidean algorithm repeatedly replaces (a, b) with (b, a mod b) until b = 0. The last non-zero remainder is the GCD. This calculator shows every step: a = q × b + r at each iteration.

Is the Miller-Rabin primality test always correct?

For numbers up to ~3.3 × 10²⁴, the set of 12 witnesses used here makes the test deterministic (no false positives). For larger numbers it reports "Too large to test."

What is modular exponentiation used for?

Modular exponentiation (Aᴮ mod C) is the core operation in RSA encryption, Diffie-Hellman key exchange, and primality testing. The fast binary method used here computes it without ever calculating the full Aᴮ, making it feasible even when B has hundreds of digits.

Why does 0! equal 1?

By convention 0! = 1. This makes combinatorics formulas consistent: C(n,0) = n!/(0!·n!) = 1, the empty product. It is also the natural extension of the recurrence n! = n·(n−1)! stepped down to n=1.

You Might Also Like

Explore 360+ Free Calculators

From math and science to finance and everyday life — all free, no account needed.