What the Big Number Calculator does
This calculator works with two numbers, X and Y, that are too large or too precise for an ordinary calculator. It supports addition, subtraction, multiplication, division, integer powers, square root, factorial, modulo, GCD and LCM. Every result is an exact decimal string, never a binary floating-point approximation. Besides the result it reports the digit count and digit sum of the integer part, the number of digits after the decimal point, and whether the result is exact. It suits students, programmers, and anyone checking number theory or cryptography exercises.
How to use it
Follow the form from top to bottom.
- Operation: choose what to compute. Square root and factorial use X only.
- X: an integer, a decimal with a point, or E-notation such as 3.5e19. No spaces or thousands separators; up to 5000 digits.
- Y: the second number, in the same formats. For a power, Y must be an integer from -10000 to 10000.
- Decimal places: from 0 to 1000. Used only by division, square root and negative powers.
- Rounding mode: half up, half even, half down, up, down, ceiling or floor. It applies only when a result must be rounded.
Formulas
Division and square root are scaled to \(d\) decimal places and rounded once:
$$q = \mathrm{round}_{mode}\left( \frac{X}{Y} \times 10^{d} \right) \times 10^{-d}$$
$$\sqrt{X} \approx \mathrm{round}_{mode}\left( \sqrt{X \times 10^{2d}} \right) \times 10^{-d}$$
Other operations:
$$n! = \prod_{k=1}^{n} k, \quad X \bmod Y = X - Y \left\lfloor \frac{X}{Y} \right\rfloor, \quad \mathrm{lcm}(a,b) = \frac{|ab|}{\gcd(a,b)}$$
Here \(X\) and \(Y\) are the operands, \(d\) is the number of decimal places, \(n\) is a whole number, and \(\mathrm{round}_{mode}\) is the chosen rounding rule. A power with a negative exponent is \(X^{-n} = 1/X^{n}\), rounded to \(d\) places.
Conventions and assumptions
- Representation: every value is an exact signed integer times a power of ten. Floats and doubles are never used.
- Input grammar: optional sign, digits with an optional fraction, optional exponent. Only ASCII digits. Inputs such as .5, 5. and +5 are valid; 1,000 and 0x10 are not.
- Exact operations: add, subtract, multiply, non-negative integer powers, factorial, modulo, GCD and LCM are never rounded and ignore the decimal places and rounding mode.
- Rounded operations: divide, square root and negative powers are rounded once from the exact value and always show exactly the chosen number of fraction digits.
- Square root: uses an integer square root with an exact remainder and tie test, so every mode is correctly rounded.
- Modulo: floored, so the result has the sign of Y. For example -7 mod 3 = 2 and 7 mod -3 = -2.
- Zero power: 0^0 = 1.
- GCD, LCM, factorial: need integers (12.0 is accepted). Results are non-negative, gcd(0,0) = 0, lcm(a,0) = 0, 0! = 1, and n is at most 3000.
- Output: plain notation without an exponent, trailing zeros stripped for exact results, and never a negative zero.
- Limits: 5000 digits per operand, exponent up to 10000, power exponent up to 10000, and at most 100000 result digits for a power.
Worked example
Multiply X = 123456789012345678901234567890 by Y = 987654321098765432109876543210. Multiplication is exact, so the decimal places (20) and rounding mode (half up) are ignored.
$$123456789012345678901234567890 \times 987654321098765432109876543210 = 121932631137021795226185032733622923332237463801111263526900$$
The result has an integer part of 60 digits, so the digit count is 60. The digits add up to 207. There are 0 digits after the decimal point, and the result is exact.
Reading the result and limitations
The result is the canonical string. The digit count and digit sum refer to the integer part only, and an integer part of 0 counts as one digit. The exact flag is true when no non-zero digits were discarded. For a division such as 1 ÷ 3 it is false, while 1 ÷ 32 with five places gives exactly 0.03125. Real-number exponents are not supported, because they cannot be exact. Inputs beyond the size limits are refused with an error code.
FAQ
Why is 0.1 + 0.2 exactly 0.3 here?
Values are stored as exact decimals, so no binary representation error occurs.
Which rounding mode should I choose?
Half up is the usual school rule. Half even reduces cumulative bias over many calculations. Down, floor, up and ceiling are directed modes.
Why does 6 ÷ 2 show 3.000?
Rounded operations use a fixed scale, so the result always shows the chosen number of decimal places.
What is the largest factorial?
The factorial is limited to n of 3000, which has 9131 digits.
How is modulo defined for negative numbers?
It is floored, so the result takes the sign of Y or is zero.
Sources
- BigDecimal (Java SE 21 & JDK 21), Oracle, Java SE 21
- RoundingMode (Java SE 21 & JDK 21), Oracle, Java SE 21
- General Decimal Arithmetic Specification, Version 1.70, IBM / speleotrove.com (M. Cowlishaw), 2009