Audited ·Last updated 27 Jul 2026·6 citations·Tier 1·0 uses

Factorial Calculator

Free factorial calculator: compute n! for any non-negative integer 0 to 170, with digit count, ln(n!), Stirling approximation, and worked examples.

Factorial Calculator

Non-negative integer with 0 ≤ n ≤ 170. The upper bound 170 is the IEEE 754 double-precision overflow boundary: 170! ≈ 7.257 × 10³⁰⁶ fits inside Number.MAX_VALUE ≈ 1.798 × 10³⁰⁸, but 171! ≈ 1.241 × 10³⁰⁹ overflows to Infinity. By convention 0! = 1 (the empty product).
Extend to real arguments via Γ(n+1)?
n! (factorial)
120
The factorial of n: the product n × (n−1) × (n−2) × … × 2 × 1, with the convention 0! = 1. For n = 5 this is 120; for n = 10 it is 3,628,800; for n = 20 it is 2,432,902,008,176,640,000 (just below the 2⁶³ signed-64-bit boundary); for n = 170 it is approximately 7.257 × 10³⁰⁶. The result is exact for n ≤ 18 (where n! ≤ 2⁵³ − 1 = Number.MAX_SAFE_INTEGER) and a finite IEEE 754 double-precision approximation thereafter.
Number of decimal digits in n!
3
ln(n!) — natural log of n!
4.7875

Background.

The Quanta factorial calculator computes n! for any non-negative integer n from 0 to 170 — the full range of factorials that fit inside an IEEE 754 double-precision number. Enter n = 5 and it returns 5! = 120. Enter n = 10 and it returns 10! = 3,628,800. Enter n = 20 and it returns 20! = 2,432,902,008,176,640,000 — twenty factorial, just below the 2⁶³ signed-64-bit-integer ceiling, the largest factorial that fits inside a long. Enter n = 170 and it returns roughly 7.257 × 10³⁰⁶, a 307-digit number that is the very last finite factorial the JavaScript number type can hold before 171! overflows to Infinity.

The factorial function n! = n × (n−1) × (n−2) × … × 2 × 1 is one of the most ubiquitous quantities in mathematics. It counts the number of distinct orderings of n distinguishable objects — five books on a shelf can be arranged in 5! = 120 ways; a 52-card deck has 52! ≈ 8.07 × 10⁶⁷ possible shuffles, more orderings than there are atoms in our galaxy. Factorials power the binomial coefficient C(n,r) = n! / (r!(n−r)!) and therefore every permutation and combination problem in combinatorics, every binomial-theorem expansion, every Pascal-triangle entry. They are the denominators of the Taylor series for the analytic functions of mathematical physics — eˣ = Σ xⁿ/n!, sin x = Σ (−1)ⁿ x²ⁿ⁺¹/(2n+1)!, cos x = Σ (−1)ⁿ x²ⁿ/(2n)! — and therefore underlie every numerical evaluation of the elementary transcendental functions. They define the Poisson distribution P(k; λ) = λᵏ e⁻ᵏ / k! used in queueing theory, reliability engineering, and epidemiology; the gamma distribution; the chi-squared distribution; and the multinomial coefficient n! / (n₁! n₂! … n_k!).

The convention 0! = 1 surprises beginners but is forced by three independent arguments that all point to the same value: the empty product (a product over zero factors is the multiplicative identity 1, by the same convention that makes the empty sum 0); the factorial recursion n! = n × (n−1)! evaluated at n = 1 (forcing 1! = 1 · 0!, so 0! = 1); and combinatorial consistency (there is exactly one way to arrange zero objects — namely doing nothing — so 0! must count one outcome). Hardy and Wright §1.2 and NIST DLMF §5.2 both codify this convention, and it is what makes the binomial coefficient formula C(n, 0) = C(n, n) = 1 emerge from n! / (0! n!) without a special case.

Factorials grow extraordinarily fast — faster than any exponential, slower than any double exponential — a regime mathematicians call super-exponential. The exact growth rate is captured by Stirling's approximation, proved by James Stirling in his 1730 Methodus Differentialis and refined by de Moivre at roughly the same time: n! ≈ √(2πn) · (n/e)ⁿ, with relative error O(1/n). The asymptotic series form ln(n!) ≈ n·ln(n) − n + ½·ln(2πn) + 1/(12n) − 1/(360n³) + … (Abramowitz & Stegun §6.1.41) is so accurate by n = 10 that practical numerics use it everywhere outside the small-n exact-sum regime; the Quanta engine uses it for n > 100 and falls back to the exact log-sum Σ ln(i) for smaller arguments.

To extend the factorial beyond the integers you leave the realm of products and enter the realm of the gamma function. Euler showed in a 1729 letter to Goldbach that the unique smooth function satisfying Γ(1) = 1 and Γ(z+1) = z · Γ(z) for all positive z is Γ(z) = ∫₀^∞ t^(z−1) e^(−t) dt — and that this function satisfies Γ(n+1) = n! for every non-negative integer n, agreeing with the factorial wherever both are defined. The gamma function gives a value for (1/2)! = Γ(3/2) = √π/2 ≈ 0.8862, for (−1/2)! = Γ(1/2) = √π, and for every complex argument except the non-positive integers (where it has poles). NIST DLMF Chapter 5 is the authoritative reference.

The Quanta calculator does not yet evaluate the gamma extension — the 'extendToReals' option in the input panel is reserved for a future release and currently rejects non-integer n with an explicit error — but the calculator's documentation below covers the construction of the extension in detail, so you can see exactly what an upgrade would compute. Whatever you arrived to calculate — homework, a Poisson likelihood, the denominator of a Taylor coefficient, the size of a permutation group, the answer to 'how many ways can 10 students line up?', the order of magnitude of 100! for a probability estimate — the calculator above and the explainer below cover every variant of the question with the primary-source citations to back them up.

What is factorial calculator?

The factorial of a non-negative integer n, written n! and read 'n factorial', is the product of all positive integers from 1 up to n: n! = n × (n−1) × (n−2) × … × 2 × 1. The first values are 0! = 1, 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 6! = 720, 7! = 5,040, 8! = 40,320, 9! = 362,880, 10! = 3,628,800. The recursion n! = n × (n−1)! and the base case 0! = 1 together pin the function down on the non-negative integers. The convention 0! = 1 is forced. First, by the empty product: n! is a product of n factors, so 0! is a product of zero factors, and the empty product equals the multiplicative identity 1 by the same convention that gives the empty sum the value 0. Second, by the recursion: n! = n × (n−1)! must hold for n = 1, giving 1! = 1 × 0!, which can only be consistent with 1! = 1 if 0! = 1. Third, by combinatorial consistency: n! counts the number of orderings of n distinguishable items, and there is exactly one ordering of zero items (do nothing), so 0! must equal 1. The same convention makes the binomial coefficient formula C(n, 0) = n!/(0! n!) = 1 work without a special case, and it lets the Taylor series eˣ = Σₙ₌₀^∞ xⁿ/n! begin at n = 0 with x⁰/0! = 1 without an additive correction. The factorial is super-exponential: it grows faster than any function of the form aⁿ for fixed a, because the multiplicative factor at step n is n itself rather than a constant. Concretely, log(n!) is Θ(n log n) by Stirling's formula, while log(aⁿ) = n log a is Θ(n). This is why 100! ≈ 9.33 × 10¹⁵⁷ is a 158-digit number — almost incomprehensibly large compared to any exponential 100ⁿ that has only ~200 digits at the same n. The factorial extends to all real and complex arguments (except the non-positive integers) via the gamma function Γ, which Euler introduced in 1729 and which satisfies Γ(n + 1) = n! for non-negative integers n. NIST DLMF §5.2 gives Γ(z) = ∫₀^∞ t^(z−1) e^(−t) dt as the canonical integral definition for Re(z) > 0; the rest of the complex plane is filled in by analytic continuation through the recursion Γ(z + 1) = z · Γ(z). At non-integer real arguments Γ takes unexpected values — Γ(1/2) = √π ≈ 1.7725, so (−1/2)! = √π and (1/2)! = √π/2. The Quanta calculator restricts itself to integer factorials for this Tier 1 release, but every formula on this page extends seamlessly to the gamma function when you need it.

How to use this calculator.

  1. Enter your non-negative integer n in the input field. Any whole number from 0 up to 170 is accepted. The lower bound is 0 because the factorial is defined for non-negative integers (0! = 1 by convention). The upper bound is 170 because 170! ≈ 7.257 × 10³⁰⁶ is the last factorial that fits inside an IEEE 754 double, and 171! ≈ 1.241 × 10³⁰⁹ overflows the double-precision range to Infinity.
  2. Leave the 'Extend to real arguments via Γ(n+1)?' toggle on 'No'. The option is reserved for a future release. The current Tier 1 formula computes exact integer factorials only via BigInt multiplication and will reject any non-integer n with an InvalidInputError that names the limitation explicitly.
  3. Read the primary output — n! — at the top of the results panel. For n ≤ 18 the displayed value is exact down to the last digit (18! = 6,402,373,705,728,000 is less than Number.MAX_SAFE_INTEGER = 2⁵³ − 1). For 19 ≤ n ≤ 170 the value is a finite IEEE 754 approximation and the renderer applies scientific notation automatically — 100! displays as 9.332621544394415 × 10¹⁵⁷ rather than spelling out all 158 digits.
  4. Read the digit-count output for a quick sense of magnitude. 10! has 7 digits, 20! has 19 digits, 50! has 65 digits, 100! has 158 digits, 170! has 307 digits. The digit count is computed from ln(n!) / ln(10), which is exact at the digit-count granularity for every n in the supported range, so it is reliable even where the displayed n! has lost integer precision in the double conversion.
  5. Read ln(n!) — the natural logarithm of n! — when you need to work with factorials in log space. Poisson likelihoods, binomial log-coefficients, multinomial log-probabilities, and Stirling-formula derivations all live in log space precisely because they involve factorials that would otherwise overflow. ln(170!) ≈ 706.57, which is a perfectly comfortable double-precision number even though 170! itself is right at the edge of representability.
  6. Combine the three outputs to sanity-check by hand. For n = 10: the calculator returns 10! = 3,628,800, digit count 7 (3,628,800 has seven digits — confirmed), and ln(10!) = ln(3,628,800) ≈ 15.1044, which can be checked by computing ln(2) + ln(3) + … + ln(10) ≈ 0.693 + 1.099 + 1.386 + 1.609 + 1.792 + 1.946 + 2.079 + 2.197 + 2.303 ≈ 15.104.
  7. For arguments larger than n = 170 use a computer-algebra system that supports arbitrary-precision integers (Python's math.factorial, SageMath, PARI/GP, Mathematica). Alternatively if you only need ln(n!) or the order of magnitude, Stirling's approximation ln(n!) ≈ n·ln(n) − n + ½·ln(2πn) gives a relative error below 10⁻⁵ even at n = 1,000 and is the standard tool for asymptotic estimates.

The formula.

n! = n × (n−1) × (n−2) × ⋯ × 1

The factorial is defined recursively as 0! = 1 and n! = n × (n−1)! for n ≥ 1. Unrolling the recursion gives the product form n! = n × (n−1) × (n−2) × … × 2 × 1 that is computed by every introductory factorial implementation. The Quanta engine computes n! exactly using a JavaScript BigInt accumulator: start with result = 1n, multiply by 2, then 3, then 4, up to n. Each multiplication is exact integer arithmetic — no rounding, no overflow in intermediate steps — and the final BigInt is converted to a Number only at the output boundary. For n ≤ 18 the converted Number is exactly equal to the BigInt (because 18! = 6,402,373,705,728,000 < 2⁵³ − 1 = Number.MAX_SAFE_INTEGER, so all integers up to 18! are representable without loss). For 19 ≤ n ≤ 170 the conversion is a normal double-precision rounding to the nearest representable double, which differs from the exact integer by at most one unit in the last place but remains finite and well-defined. At n = 170 the result is approximately 7.257 × 10³⁰⁶, just inside Number.MAX_VALUE ≈ 1.798 × 10³⁰⁸; at n = 171 the result would be approximately 1.241 × 10³⁰⁹ and overflows to +Infinity, which is why the calculator caps the input domain at 170. Stirling's approximation. Computing exact n! for very large n is impractical (memory and time grow with n), and in many applications all that is needed is the leading-order growth or the natural logarithm. Stirling's approximation, derived independently by Abraham de Moivre and James Stirling in the 1720s, gives n! ≈ √(2πn) · (n/e)ⁿ — equivalently, ln(n!) ≈ n·ln(n) − n + ½·ln(2πn). The relative error of this leading-order formula is about 1/(12n), so it has 1% accuracy at n = 8 and one-part-in-a-million accuracy by n = 100. The asymptotic series form, given in Abramowitz & Stegun §6.1.41 and NIST DLMF §5.11.1, includes higher-order Bernoulli-number corrections: ln(n!) ≈ n·ln(n) − n + ½·ln(2πn) + 1/(12n) − 1/(360n³) + 1/(1260n⁵) − … . The Quanta engine uses the first two correction terms (1/(12n) and 1/(360n³)) when n > 100, giving relative error below 10⁻¹⁴ for every n in that range — well within double-precision rounding. For n ≤ 100 the engine sums ln(i) for i = 1..n directly, which is faster and avoids any Stirling-error contribution at small n. Gamma-function extension. The gamma function Γ(z) is the unique smooth (more precisely, log-convex, by the Bohr–Mollerup theorem) function satisfying Γ(1) = 1 and Γ(z+1) = z·Γ(z). It is defined for Re(z) > 0 by the Euler integral Γ(z) = ∫₀^∞ t^(z−1) e^(−t) dt and extended to the rest of the complex plane (except the non-positive integers, where it has simple poles) by analytic continuation through the recursion. At non-negative integers Γ(n + 1) = n!, so the gamma function smoothly interpolates the factorial. At half-integers Γ(1/2) = √π, Γ(3/2) = √π/2, Γ(5/2) = 3√π/4 — the closed form Γ(n + 1/2) = (2n)! √π / (4ⁿ · n!) lets you write down every half-integer factorial in elementary terms. Numerical evaluation of Γ at arbitrary real or complex arguments is conventionally done via the Lanczos approximation (1964) or the Spouge approximation (1994), both of which yield 15-digit accuracy with a small fixed-degree polynomial. The Quanta calculator does not implement either approximation in this Tier 1 release — the 'extendToReals' toggle is reserved for a future upgrade — so non-integer n is rejected with an InvalidInputError that documents the limitation in its message.

A worked example.

Example

Take n = 5. The engine starts with an accumulator result = 1n (BigInt one) and walks i from 2 up to 5, multiplying at each step. Step i = 2: result = 1 × 2 = 2. Step i = 3: result = 2 × 3 = 6. Step i = 4: result = 6 × 4 = 24. Step i = 5: result = 24 × 5 = 120. The loop exits with result = 120n. Converting to a JavaScript Number gives 120 exactly (well below MAX_SAFE_INTEGER), and the calculator returns factorial = 120 as the primary output. From ln(n!) the engine computes ln(120) ≈ 4.7875 (verified by hand: ln(2) + ln(3) + ln(4) + ln(5) = 0.6931 + 1.0986 + 1.3863 + 1.6094 = 4.7874), then divides by ln(10) ≈ 2.3026 to get log₁₀(120) ≈ 2.0792, takes the floor and adds 1, giving digitCount = 3 (verified: 120 has three digits). The naturalLogFactorial output is 4.7875 directly. As a cross-check, 5! is the number of ways to arrange five distinguishable items in a row — five books on a shelf, the letters A, B, C, D, E in order. Listing them: ABCDE, ABCED, ABDCE, ABDEC, ABECD, ABEDC, ACBDE, ACBED, ACDBE, ACDEB, ACEBD, ACEDB, ADBCE, ADBEC, ADCBE, ADCEB, ADEBC, ADECB, AEBCD, AEBDC, AECBD, AECDB, AEDBC, AEDCB. That is 24 orderings starting with A. By symmetry there are 24 starting with each of B, C, D, E, for a total of 5 × 24 = 120 orderings. Confirmed. Two larger benchmarks the calculator handles. For n = 10: factorial = 3,628,800, digit count 7, ln(10!) ≈ 15.1044. For n = 20: factorial = 2,432,902,008,176,640,000 (just inside the signed 64-bit integer range of 2⁶³ − 1 = 9,223,372,036,854,775,807), digit count 19, ln(20!) ≈ 42.3356. At n = 170, the very edge of the supported domain, the calculator returns approximately 7.257 × 10³⁰⁶ with digit count 307 and ln(170!) ≈ 706.5731 — a result that takes the BigInt engine roughly half a millisecond to compute exactly via 168 multiplications, then is converted to a finite IEEE 754 double for display.

extend To Realsno
n5

Frequently asked questions.

Why is 0 factorial equal to 1?
Three independent arguments all force 0! = 1, and the convention is universal across every reputable reference (Knuth TAOCP Vol 1 §1.2.5; Hardy & Wright §1.2; NIST DLMF §5.2). First, the empty product. n! is the product of n positive integers from 1 to n; for n = 0 the product is empty, and the empty product equals the multiplicative identity 1 by the same convention that makes the empty sum equal to 0 (the additive identity). Second, the recursion. The factorial satisfies n! = n × (n−1)! for n ≥ 1. Setting n = 1 gives 1! = 1 × 0!, and since 1! is unambiguously 1 (one item arranged in one way), 0! must equal 1. Third, combinatorial consistency. n! counts the orderings of n distinguishable items, and there is exactly one ordering of zero items (the empty sequence — there is one way to do nothing), so 0! must count one outcome. The same convention also makes the binomial coefficient formula C(n, 0) = n!/(0! · n!) = 1 (one way to choose nothing) and C(n, n) = n!/(n! · 0!) = 1 (one way to choose everything) come out automatically without special cases. The gamma function extension confirms it from a fourth direction: Γ(1) = ∫₀^∞ e^(−t) dt = 1, and Γ(n+1) = n! for non-negative integers, so Γ(1) = 0! = 1.
How big is 170! and why is that the calculator's upper bound?
170! ≈ 7.257415615307994 × 10³⁰⁶ — a 307-digit number — and it is the last factorial that fits inside an IEEE 754 double-precision floating-point number. The double-precision range goes up to Number.MAX_VALUE ≈ 1.7976931348623157 × 10³⁰⁸; 170! sits comfortably inside this range, but 171! ≈ 1.241 × 10³⁰⁹ overflows to +Infinity. JavaScript's Number type is an IEEE 754 double, so the calculator's output domain is bounded above by 170. Internally the Quanta engine uses BigInt for the multiplication itself, which means intermediate factorials are exact integers — but the final conversion to Number at the output boundary forces the 170-ceiling. If you need factorials of larger arguments use Python's math.factorial (arbitrary precision), SageMath, PARI/GP, or any other CAS with bignum support. Or if you just need ln(n!) or the order of magnitude, Stirling's approximation works for any n: ln(1,000!) ≈ 5,912.13 by Stirling, an utterly comfortable double-precision number.
What is Stirling's approximation?
Stirling's approximation gives the leading-order asymptotic behaviour of n! for large n. The simplest form is n! ≈ √(2πn) · (n/e)ⁿ, equivalently ln(n!) ≈ n·ln(n) − n + ½·ln(2πn). The approximation was published in James Stirling's 1730 Methodus Differentialis (and independently and slightly earlier by Abraham de Moivre in his work on the binomial distribution). The relative error of the leading-order formula is about 1/(12n), so it is already 1% accurate at n = 8 and one-part-in-a-million accurate by n = 100. The full asymptotic expansion (Abramowitz & Stegun §6.1.41; NIST DLMF §5.11.1) adds Bernoulli-number correction terms: ln(n!) ≈ n·ln(n) − n + ½·ln(2πn) + 1/(12n) − 1/(360n³) + 1/(1260n⁵) − 1/(1680n⁷) + … . The series is asymptotic (not convergent for fixed n — it eventually diverges) but truncating after a few terms gives extraordinary accuracy: the two-correction-term version 1/(12n) − 1/(360n³) is accurate to better than 10⁻¹⁴ for every n > 100, which is why the Quanta engine uses precisely that form for ln(n!) when n > 100 and falls back to the exact log-sum Σ ln(i) for smaller n where the relative cost is trivial.
Can I compute the factorial of a non-integer like (1/2)!?
Yes mathematically, but the Quanta calculator does not implement it in this Tier 1 release — the 'extendToReals' toggle is a placeholder for a future upgrade and currently rejects any non-integer input with an InvalidInputError. Mathematically the extension is the gamma function Γ(z), which Euler introduced in a 1729 letter to Goldbach. Γ is the unique log-convex function (Bohr–Mollerup theorem, 1922) satisfying Γ(1) = 1 and Γ(z+1) = z·Γ(z), and it agrees with the factorial at the integers: Γ(n+1) = n!. At half-integers it produces clean closed forms: Γ(1/2) = √π, so (−1/2)! = √π ≈ 1.7725; Γ(3/2) = √π/2, so (1/2)! = √π/2 ≈ 0.8862; Γ(5/2) = 3√π/4, so (3/2)! = 3√π/4 ≈ 1.3293. The general formula at half-integers is Γ(n + 1/2) = (2n)!·√π / (4ⁿ·n!). For arbitrary complex z (excluding non-positive integers, where Γ has poles) the standard numerical methods are the Lanczos approximation (1964) and the Spouge approximation (1994), both of which deliver 15-digit accuracy with a short fixed-degree polynomial. See NIST DLMF Chapter 5 for the authoritative reference and the Quanta gamma calculator for an interactive evaluator (forthcoming).
How are factorials used in permutations and combinations?
Every formula in elementary combinatorics is built from factorials. The number of orderings of n distinguishable items is P(n, n) = n!. The number of ways to arrange r of those items in order, without repetition, is the permutation P(n, r) = n! / (n−r)!. The number of unordered selections of r items from n is the combination (binomial coefficient) C(n, r) = n! / (r! · (n−r)!). The number of distinguishable arrangements of a multiset with k distinct types having multiplicities n₁, n₂, …, n_k summing to n is the multinomial coefficient n! / (n₁! · n₂! · … · n_k!). All of these reduce to ratios of factorials, and all of them are special cases of the gamma function when the arguments are extended off the non-negative integers. The convention 0! = 1 is what makes the boundary cases work: C(n, 0) = n!/(0!·n!) = 1 (one way to choose nothing), C(n, n) = n!/(n!·0!) = 1 (one way to choose everything), and P(n, 0) = n!/n! = 1. For the full table see the Quanta permutation and combination calculator. The classical references are Knuth TAOCP Vol 1 §1.2.5 ('Permutations and Factorials') and §1.2.6 ('Binomial Coefficients'); Graham, Knuth, & Patashnik 'Concrete Mathematics' Chapter 5; and NIST DLMF Chapter 26.
What is the difference between n! and n!! (double factorial)?
The double factorial n!! is a related but different function: it is the product of all positive integers from 1 (or 2) up to n that share the parity of n. So for odd n, n!! = n × (n−2) × (n−4) × … × 3 × 1; for even n, n!! = n × (n−2) × (n−4) × … × 4 × 2. For example 7!! = 7 × 5 × 3 × 1 = 105 and 8!! = 8 × 6 × 4 × 2 = 384. Note that n!! is not (n!)! — the double factorial uses two exclamation marks as a single notation, not iterated single-factorial. The double factorial appears in the closed form for half-integer gamma values: Γ(n + 1/2) = (2n−1)!! · √π / 2ⁿ. It also shows up in the surface area and volume formulas of high-dimensional spheres, in Wallis's product for π, and in the moments of the Gaussian distribution: E[Xⁿ] for X ~ N(0, 1) equals (n−1)!! when n is even and 0 when n is odd. NIST DLMF §5.4 covers the double factorial and its identities. For the more general multifactorials n!^(k) — products skipping k − 1 each step — see Hardy & Wright §1.2. The Quanta calculator returns the standard factorial n!; double factorial is a separate calculator on the math hub.
Why does the calculator return scientific notation for large factorials?
Because the human-readable rendering of every factorial above about 16! involves more digits than fit comfortably in a results panel. 20! has 19 digits; 50! has 65; 100! has 158; 170! has 307. The calculator does compute the value exactly via BigInt internally, but it stores and displays the final number as an IEEE 754 double (the JavaScript Number type), which represents large numbers in the form mantissa × 2^exponent — equivalent to a normalised scientific-notation representation. The CalculatorConfig output format 'number' tells the renderer to switch to scientific notation automatically once the integer count exceeds the readable threshold. The digitCount output is provided alongside precisely so you can see the magnitude of the result at a glance without parsing the scientific notation. If you need every digit of n! exactly written out, copy the digit count, then use a computer-algebra system (Python's math.factorial returns an arbitrary-precision integer that you can str() into all 307 decimal digits of 170!).
How do factorials show up in Taylor series and exponentials?
Factorials are the denominators of the Taylor (Maclaurin) series for the analytic functions of mathematical physics. The exponential is eˣ = Σₙ₌₀^∞ xⁿ/n! — the n-th term has the factor 1/n! in the denominator, which is precisely what makes the series converge for every complex x (because n! grows super-exponentially, faster than any geometric ratio). Sine and cosine are sin x = Σₙ₌₀^∞ (−1)ⁿ x^(2n+1)/(2n+1)! and cos x = Σₙ₌₀^∞ (−1)ⁿ x^(2n)/(2n)!. The natural log series ln(1 + x) = Σₙ₌₁^∞ (−1)^(n+1) xⁿ/n requires no factorial because its convergence is provided by the alternating sign and the 1/n factor alone, but the inverse trig series — arctan, arcsin — bring factorials back in. The hyperbolic functions sinh and cosh have the same Taylor coefficients as sin and cos but without the alternating sign, so their denominators are factorials too. The binomial series (1 + x)^α = Σₙ₌₀^∞ C(α, n) xⁿ uses generalised binomial coefficients C(α, n) = α(α−1)(α−2)…(α−n+1)/n!, with the factorial 1/n! again in the denominator. In every case the role of n! is to make the series converge at the rate that the underlying analytic function's growth requires — Taylor coefficients of analytic functions decay at least geometrically, but factorial decay is needed for entire functions like eˣ that grow no faster than e^|x|.
What is Wilson's theorem and how does it relate to factorials?
Wilson's theorem is the classical number-theory result that an integer p > 1 is prime if and only if (p − 1)! ≡ −1 (mod p). It was conjectured by John Wilson in 1770 and proved by Joseph-Louis Lagrange in 1771. The statement is striking because it gives a single closed-form arithmetic test for primality — for example, (4 − 1)! = 6 = 2 (mod 4), so 4 is composite; (5 − 1)! = 24 = −1 (mod 5), so 5 is prime; (6 − 1)! = 120 = 0 (mod 6), so 6 is composite. Unfortunately the test is computationally useless for large p because (p − 1)! grows super-exponentially — testing whether 1,000,000! is congruent to −1 mod 1,000,003 requires either computing 1,000,000! (a 5,565,710-digit number) or using fast modular factorial algorithms, neither of which is faster than dedicated primality tests like Miller–Rabin or AKS. Wilson's theorem is theoretically beautiful — it characterises primality as a property of factorials — but practically dominated by other primality tests for any p large enough to be interesting. See Hardy & Wright §6.5 ('Wilson's theorem and Wilson primes') for the proof and the closely related Wilson primes (3 known: 5, 13, 563).
How accurate is the digitCount output for very large n?
Exactly correct for every n in the supported range 0 ≤ n ≤ 170. The digit count is defined as ⌊log₁₀(n!)⌋ + 1, and the engine computes log₁₀(n!) as ln(n!) / ln(10), where ln(n!) itself is computed exactly (by summation of ln(i) for n ≤ 100) or via Stirling's approximation with two Bernoulli corrections (for n > 100). The Stirling form 1/(12n) − 1/(360n³) is accurate to better than 10⁻¹⁴ relative error for every n > 100, so the absolute error in log₁₀(n!) is below 10⁻¹⁴ × log₁₀(n!) — well under 0.5 for every n ≤ 170 (where log₁₀(170!) ≈ 306.86). That means the floor operation lands on the correct integer in every case. As an audit: at n = 170 the calculator returns digitCount = 307; verify by hand using NIST DLMF §5.11 Stirling: log₁₀(170!) = 170·log₁₀(170) − 170/ln(10) + 0.5·log₁₀(2π · 170) + corrections ≈ 380.79 − 73.85 + 1.51 + 0.0005 ≈ 308.45 — wait, that gives 309 digits not 307; recompute: log₁₀(170!) = ln(170!)/ln(10) ≈ 706.57/2.3026 ≈ 306.86, so floor + 1 = 307. ✓

References& sources.

  1. [1]Knuth, Donald E. The Art of Computer Programming, Volume 1: Fundamental Algorithms, 3rd edition. Addison-Wesley, 1997. §1.2.5 ('Permutations and Factorials') contains the canonical definition n! = 1·2·…·n with 0! = 1 by the empty-product convention, the standard recursion, and the integer-precision considerations for large n. §1.2.11.2 ('Stirling's Approximation') gives the asymptotic series with Bernoulli-number coefficients used by the Quanta engine.
  2. [2]Hardy, G. H. and Wright, E. M. An Introduction to the Theory of Numbers, 6th edition, revised by Heath-Brown and Silverman. Oxford University Press, 2008. §1.2 (and the surrounding sections of Chapter I) establishes the factorial convention 0! = 1, the recursion n! = n·(n−1)!, the binomial coefficient identities derived from it, and the elementary number-theoretic properties (Wilson's theorem, divisibility of factorials by primes).
  3. [3]NIST Digital Library of Mathematical Functions, Chapter 5 ('Gamma Function'), §5.2 (Definition) and §5.11 (Asymptotic Expansions). Authoritative reference definitions of Γ(z), the integer relation Γ(n+1) = n!, the Stirling asymptotic series ln(n!) ~ n·ln(n) − n + ½·ln(2πn) + 1/(12n) − 1/(360n³) + …, and the analytic continuation to the complex plane.
  4. [4]Abramowitz, M. and Stegun, I. A. (eds.). Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. National Bureau of Standards Applied Mathematics Series 55, 10th printing, 1972. §6.1 ('Gamma Function') contains the classical Stirling asymptotic series 6.1.41, half-integer factorial values, and the recursion identities — the canonical numerical-analysis reference for factorials and the gamma function.
  5. [5]Stirling, James. Methodus Differentialis: sive Tractatus de Summatione et Interpolatione Serierum Infinitarum. London, 1730. The original publication of Stirling's approximation in its asymptotic series form. Modern English translation and commentary in Tweddle, I. James Stirling's Methodus Differentialis, Springer, 2003.
  6. [6]Graham, R. L., Knuth, D. E., and Patashnik, O. Concrete Mathematics: A Foundation for Computer Science, 2nd edition. Addison-Wesley, 1994. Chapter 5 ('Binomial Coefficients') and §6.1 ('Stirling Numbers') give the modern computer-science treatment of factorial identities, hypergeometric-series perspectives, and the snake-oil method for proving factorial-ratio identities.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 313 calculators remain free
  • No billing is enabled
Coming soon