CalcTrace

Big Number Calculator

Do exact arithmetic on whole numbers and decimals far longer than an ordinary calculator can hold. Add, subtract, multiply, divide to as many decimal places as you choose, raise to a power, or find a factorial, remainder or greatest common divisor. Every digit of the answer is correct, and the digit count is shown.

Last updated .

Your numbers

Operation

Each number can have up to 5,000 digits, with a minus sign and a decimal point if needed. Commas and spaces are ignored, and 1.5e30 is read as 1.5 × 1030.

Result

A × B

–

–Digits in the answer
–Scientific notation
–Digits in A
–Digits in B

Show the working

    Why ordinary calculators lose digits

    Almost every calculator app, spreadsheet and programming language stores a number in a fixed 64 bits, in a format called double-precision floating point. Of those bits, 53 hold the significant digits, and the rest hold the sign and the position of the point. Fifty-three binary digits are worth just under 16 decimal digits, so that is all the precision there is.

    Largest run of consecutive whole numbers: up to 253 = 9,007,199,254,740,992

    Above that value the format can no longer store every whole number, only every second one, then every fourth, and so on. Ask an ordinary calculator for 9,007,199,254,740,992 + 1 and it answers 9,007,199,254,740,992, because the true answer, which ends in 993, has no slot. Multiply 123,456,789 by 987,654,321 and it reports 121,932,631,112,635,260, while the exact product is 121,932,631,112,635,269. Decimals suffer too: 0.1 and 0.2 have no exact binary form, which is why 0.1 + 0.2 comes out as 0.30000000000000004.

    This calculator does not use that format. It stores each number as a whole number of unlimited length, together with a note of where the decimal point sits, and works the way you do on paper.

    The method

    A decimal with d places = (whole number N) ÷ 10d

    N is the number with its decimal point removed and d is the count of digits that were after the point, so 12.345 is stored as N = 12345 with d = 3. Arithmetic then needs only whole numbers:

    Add or subtract: give both numbers the same d, then add or subtract the N values

    Multiply: multiply the N values and add the d values

    Divide to p places: (NA × 10p + dB) ÷ (NB × 10dA), as a whole-number division

    In the division rule, p is the number of decimal places you ask for and the subscripts A and B mark which number each N and d belongs to. The leftover remainder decides whether the last place rounds up. Addition, subtraction, multiplication, powers and factorials are always exact. Division is exact only when the decimal ends within the places you chose: 1 ÷ 8 = 0.125 exactly, but 1 ÷ 7 to 20 places is 0.14285714285714285714 and continues for ever.

    Worked example: 4,294,967,296 squared by hand

    Long numbers are multiplied in blocks, exactly as software does it. Split 4,294,967,296 (which is 232) into a high block and a low block of six digits: 4,294 and 967,296, so the number is 4,294 × 106 + 967,296.

    1. High × high. 4,294 × 4,294 = 18,438,436. This block is worth 1012.
    2. High × low, twice. 4,294 × 967,296 = 4,153,569,024, and doubling gives 8,307,138,048. This block is worth 106.
    3. Low × low. 967,296 × 967,296 = 935,661,551,616.
    4. Shift and add. 18,438,436,000,000,000,000 + 8,307,138,048,000,000 + 935,661,551,616 = 18,446,744,073,709,551,616.

    That 20-digit result is 264. A floating-point calculator shows it as 18,446,744,073,709,552,000, correct only to its first 16 digits.

    How large the answers get

    Factorials and powers grow far faster than intuition suggests. 20! = 2,432,902,008,176,640,000 is the last factorial below 9,223,372,036,854,775,807, the limit of a 64-bit signed integer, and 21! is already past it. 25! = 15,511,210,043,330,985,984,000,000 has 26 digits. 100! has 158 digits and 1,000! has 2,568. The power 2100 is 1,267,650,600,228,229,401,496,703,205,376, with 31 digits.

    The zeros at the end of a factorial can be counted without computing it. Each one needs a factor of 10, which is a 2 and a 5, and fives are the scarcer of the two:

    Trailing zeros of n! = ⌊n ÷ 5⌋ + ⌊n ÷ 25⌋ + ⌊n ÷ 125⌋ + …

    The brackets mean “round down to a whole number”. For 25! that is 5 + 1 = 6 zeros, for 100! it is 20 + 4 = 24, and for 1,000! it is 200 + 40 + 8 + 1 = 249.

    Practical points