Factorial
The factorial of a whole number n is the product of every whole number from 1 up to n, and 0! is defined as 1. The Rust WASM Calculator computes factorials for n between 0 and 20 inclusive using 64-bit unsigned integer arithmetic. Press n! with a whole number on the display and the result replaces it. Anything outside that range is refused with an explicit error rather than a wrapped or approximated number.
Why the limit is 20
A 64-bit unsigned integer holds values up to 18446744073709551615. The factorial of 20 is 2432902008176640000, which fits. The factorial of 21 is 51090942171709440000, which does not. Rather than switch to floating point and start returning approximations, the implementation refuses any input above 20 and returns the error “Factorial overflow: n must be <= 20”.
The guard is belt and braces: the function checks n against 20 before it starts multiplying, and the multiplication loop itself uses Rust's checked multiplication, which returns an error instead of wrapping if a product ever exceeds the 64-bit range. Both paths are covered by the crate's unit tests, including explicit cases for 21, 25, and 100.
Factorials from 0 to 20
These are the exact values the calculator returns. They are integers, not floating point approximations, so the digits are correct all the way to the last one.
- 0! = 1 and 1! = 1
- 2! = 2, 3! = 6, 4! = 24, 5! = 120
- 10! = 3628800
- 15! = 1307674368000
- 20! = 2432902008176640000
Using the n! button
Type a whole number and press n!. The page parses the display as an integer first, so a decimal point is truncated, and it then refuses anything negative or above 20 with its own message before the value reaches WebAssembly. The result appears on the display and is added to the on-screen history list, though not to the Rust-side calculation history, which records only the four binary arithmetic operations.
The exported function itself takes a 64-bit float rather than an unsigned integer. That is deliberate: it means a negative, fractional or non-finite argument arrives at the Rust side intact and is rejected by name, instead of being silently truncated or wrapped by the conversion on the way in. The errors page covers both factorial errors.
Questions and answers
What is the largest factorial this calculator can compute?
20 factorial, which is 2432902008176640000. That is the largest factorial that fits in a 64-bit unsigned integer. Any input above 20 returns the error Factorial overflow: n must be <= 20.
What is 0 factorial?
One. The calculator returns 1 for both 0! and 1!, which matches the standard mathematical definition.
Can the calculator compute the factorial of a decimal?
No. The display value is parsed as an integer before it reaches the WebAssembly module, so a decimal point is truncated. Negative values are rejected with an invalid input message.