Supported operations
The Rust WASM Calculator supports seven mathematical operations through its keypad and two more through its JavaScript API. Every operation is implemented in Rust in a single source file and compiled to WebAssembly. This page lists each one, the exact method it calls, the values it accepts, and what happens when an input falls outside the accepted range.
The four arithmetic operators
Addition, subtraction, multiplication, and division all operate on the calculator's stored value and one new operand. Each one replaces the stored value with the result and appends an entry to the Rust-side calculation history. All four use 64-bit floating point, so results follow IEEE 754 rules: adding 0.1 and 0.2 yields 0.30000000000000004, not exactly 0.3.
- Add (+) — returns the stored value plus the operand. Always succeeds.
- Subtract (−) — returns the stored value minus the operand. Always succeeds.
- Multiply (×) — returns the product. Always succeeds.
- Divide (÷) — returns the quotient, or the error “Division by zero” when the operand is exactly zero.
Division is the only one of the four that can fail. It is checked before the division is performed rather than after, so a divide-by-zero leaves the stored value untouched and you can immediately retry with a different operand.
Square root and squaring
Square root and squaring both act on the displayed value alone and take no second operand. Square root rejects negative inputs with the error “Cannot take square root of negative number” instead of returning NaN, so a mistyped minus sign produces a visible error rather than a value that quietly poisons every later calculation. The square root of zero returns zero and the square root of one returns one.
The x² button calls a general power method with an exponent of 2. That method accepts any 64-bit float exponent, so it also handles fractional exponents such as 0.5 and negative exponents such as −2, though the keypad only ever passes 2. Neither square root nor squaring writes to the Rust-side calculation history.
Factorial
The n! button computes the factorial of a whole number between 0 and 20 inclusive. The core computes in 64-bit unsigned integer arithmetic, where 20! is 2432902008176640000, the largest factorial that fits; the value crosses back to JavaScript as a float, which represents every result up to 20! exactly. The page screens the display value first and shows its own message for anything that is not a whole number in range, so the module's overflow and invalid input errors are reached only through the JavaScript API. See the factorial page for the full table.
Memory and history
Four buttons drive a single memory register: MS stores the display value, MR recalls it into the display, MC resets it to zero, and M+ adds the display value to whatever the register already holds. The register is a separate field from the calculator's working value, so pressing C clears the display without clearing memory. Details are on the memory page.
The history panel shows the five most recent calculations, newest first, and the counter beside the heading shows the running total. Details are on the history page.
Functions with no keypad button
Two functions are exported by the WebAssembly module and imported by the page's JavaScript, but no button calls them. They are available to anyone importing the module directly.
percentage(value, percent)— returns value multiplied by percent divided by 100. See the percentage page.compound_interest(principal, rate, years, compounds_per_year)— see the compound interest page.
Questions and answers
Which calculator operations can return an error?
Four are defined. Division returns an error when the divisor is exactly zero, square root returns an error for negative inputs, and factorial returns either an overflow error above 20 or an invalid input error for a negative or fractional argument. Every other operation always returns a value.
Does the calculator support fractional or negative exponents?
The underlying power method accepts any 64-bit float exponent, including 0.5 and negative values, but the keypad only exposes the x squared button, which always passes an exponent of 2.