Big Number Calculator: Exact Arithmetic on Numbers with Thousands of Digits
By FindMySum · Last reviewed
A big number calculator does arithmetic on numbers too large, or too precise, for an ordinary calculator. This one adds, subtracts, multiplies and divides numbers with thousands of digits, raises them to powers, takes roots and finds the greatest common divisor, the least common multiple, remainders and factorials. Whole-number results are exact to the last digit. Decimal results are exact where that is possible, and rounded to a number of decimal places you choose where it isn't.
Why ordinary calculators lose digits
Almost every calculator, spreadsheet and programming language stores numbers in 64-bit binary floating point (IEEE 754 double precision). It keeps a 53-bit significand, which is about 15 to 17 decimal digits, plus an exponent. That is plenty for measurements, but it means:
- Whole numbers above 2^53 (about 9 × 10^15) can't all be stored, so 2^100 becomes 1.26765E+30 and its last 16 digits are lost.
- Numbers above about 1.8 × 10^308 overflow to infinity, so 171! can't be computed at all.
- Many short decimals, like 0.1, have no exact binary form, which is why 0.1 + 0.2 gives 0.30000000000000004.
Arbitrary-precision arithmetic stores as many digits as the number needs. The calculator uses JavaScript's built-in BigInt for whole numbers and the decimal.js library for decimals. Both run in your browser.
What each operation does
Addition, subtraction and multiplication are exact for any inputs. Multiplying a 30-digit number by another 30-digit number gives a 59- or 60-digit result, and every digit is shown.
Division of whole numbers gives three things: the whole-number quotient, the remainder and the decimal value to the number of places you choose. 1 ÷ 7 to 30 places is 0.142857 142857 142857 142857 142857 142857 (digits grouped in sixes here); the six-digit block repeats forever, so any finite answer is rounded.
Powers with a whole-number exponent are exact: 2^100 = 1 267 650 600 228 229 401 496 703 205 376. A negative exponent gives a reciprocal, rounded to your decimal places, and a fractional exponent such as 2^0.5 is computed with logarithms at high precision.
Roots use the index B: B = 2 for a square root, 3 for a cube root. If A is a perfect power the root is exact, otherwise it is rounded: √2 to 50 places is 1.41421 35623 73095 04880 16887 24209 69807 85696 71875 37695 (grouped in fives here).
GCD and LCM use the Euclidean algorithm, which takes only a few hundred steps even for numbers with hundreds of digits. LCM(A, B) = |A × B| ÷ GCD(A, B).
Factorial multiplies 1 × 2 × … × n. 100! has 158 digits and ends in 24 zeros; the calculator handles n up to 25,000, whose factorial has about 99,000 digits.
Remainders of negative numbers
For positive numbers, 17 mod 5 = 2 everywhere. For negative numbers there are two conventions, and both are in common use:
- Truncated remainder: the quotient is rounded toward zero, so the remainder has the sign of the dividend. −17 rem 5 = −2, because −17 = 5 × (−3) − 2. JavaScript, C, C++ and Java's % operator work this way.
- Floored modulo: the quotient is rounded down, so the result has the sign of the divisor. −17 mod 5 = 3, because −17 = 5 × (−4) + 3. Python's %, Excel's MOD and most mathematics texts work this way.
The calculator shows both, so you can match whichever system you are checking.
Worked example: 2^100
The calculator opens with A = 2, B = 100 and the power operation.
- Exact result: 2^100 = 1 267 650 600 228 229 401 496 703 205 376 (digits grouped in threes here).
- Digit count: 31, which matches ⌊100 × log₁₀ 2⌋ + 1 = ⌊30.103⌋ + 1.
- Scientific notation: 1.26765060022823 × 10^30, rounded to 15 significant digits.
- Compare: a spreadsheet shows 1.26765E+30 and, if you format it as a whole number, prints 1 267 650 600 228 230 000 000 000 000 000, with the last 16 digits replaced by zeros.
Entering numbers
Type or paste digits; spaces, commas and underscores are ignored, so 1,000,000 and 1 000 000 both work. E-notation is accepted (6.02214076e23, 1e-50), and a leading minus sign makes a number negative. Each input can be up to 5,000 characters, and the result is limited to 100,000 digits. Results that would be larger are refused with an estimate of their size, worked out from logarithms, before any work is done.
Limits
The calculator works with real numbers in base 10. It doesn't do complex numbers, fractions typed as a/b, other number bases or non-integer factorials (the gamma function). Rounded results use round-half-away-from-zero at the last place you ask for; increase the decimal places if you need more digits.
More questions
What is the largest number a normal computer can store exactly?
In standard double-precision floating point, which JavaScript, Excel and most calculators use, every integer up to 2^53 = 9,007,199,254,740,992 is exact. Above that, only some integers can be stored and the rest are rounded to a neighbour; the largest finite value is about 1.8 × 10^308. Arbitrary-precision libraries like BigInt and decimal.js remove both limits.
What is a googol and a googolplex?
A googol is 10^100, a 1 followed by 100 zeros, so it has 101 digits. A googolplex is 10^googol: it has a googol plus one digits, far more than there are atoms in the observable universe, so no computer can write it out. The calculator can show a googol in full.
Why does 0.1 + 0.2 not equal 0.3 on some computers?
Binary floating point can't represent 0.1 or 0.2 exactly, just as a decimal can't write 1/3 exactly. The stored values are slightly off, and their sum is 0.30000000000000004. Decimal arithmetic, which this calculator uses for numbers with a decimal point, stores 0.1 exactly and gives 0.3.
How many digits does a power have?
The number of digits of a positive whole number N is ⌊log₁₀ N⌋ + 1. For a power a^b that is ⌊b·log₁₀ a⌋ + 1, so 2^100 has ⌊100 × 0.30103⌋ + 1 = 31 digits and 2^1000 has 302. The calculator uses this estimate to refuse results over 100,000 digits before trying.
Where are numbers this large used?
Cryptography is the main everyday use: RSA keys are products of two primes with hundreds of digits each, and the arithmetic is modular exponentiation on 2048-bit numbers. Combinatorics produces huge counts such as 52! ≈ 8.07 × 10^67 orderings of a deck of cards, and number theory searches for primes and digits of constants with millions of digits.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.