Rust WASM Calculator: what it is and what it computes
The Rust WASM Calculator is a free browser calculator whose arithmetic engine is written in Rust and compiled to WebAssembly. It computes addition, subtraction, multiplication, division, square root, squaring, and factorial, and it keeps a running memory register and a list of recent calculations. Every number is held as a 64-bit float. Factorial is computed in 64-bit unsigned integer arithmetic inside Rust and crosses back to JavaScript as a float, which is exact for every value it accepts. Nothing you type is sent anywhere: the WebAssembly module is downloaded once and every calculation runs locally inside the page.
What this calculator computes
The on-screen keypad exposes 24 buttons. Four of them drive the memory register, four drive arithmetic operators, one clears the display, ten enter digits, one enters a decimal point, and the rest cover square root, squaring, equals, and factorial. Pressing an operator stores the current display value in the Rust Calculator struct; pressing equals sends the second operand across the WebAssembly boundary and writes the result back to the display.
- Addition, subtraction, multiplication, division — the four binary operators, each recorded in the Rust-side calculation history.
- Square root — the √ button; rejects negative inputs with an explicit error rather than returning NaN.
- Squaring — the x² button, which calls the general
powermethod with an exponent of 2. - Factorial — the n! button, defined for whole numbers 0 through 20.
- Memory — MS stores, MR recalls, MC clears, and M+ adds the display value to the register.
- History — the five most recent calculations, newest first.
Two further functions ship inside the WebAssembly module and are importable from JavaScript but have no keypad button: percentage(value, percent) and compound_interest(principal, rate, years, compounds_per_year). They are documented on the percentage and compound interest pages.
Why Rust and WebAssembly
The arithmetic lives in Rust rather than JavaScript so that the failure cases are part of the type system instead of an afterthought. Division and square root return a Rust Result, and factorial uses checked_mul so an overflow becomes an error value rather than a silently wrapped number. Those Result types cross into JavaScript as thrown exceptions, which means the page cannot display a wrong answer where it should have displayed an error.
WebAssembly is what lets that Rust code run in a browser tab with no server round trip. The crate is built with wasm-pack build --target web and compiled with opt-level = "z" and link-time optimization enabled, which keeps the shipped module small enough to fetch on first paint. The full reasoning is on the why Rust and WebAssembly page.
Reference pages
Each operation has its own page with the exact behaviour, the edge cases, and the error text you will see if an input is out of range.
- Every supported operation — the complete reference.
- Factorial — why the limit is 20.
- Memory functions — MS, MR, MC, and M+.
- Calculation history — what is recorded and what is not.
- Error messages — all four of them, verbatim.
- Frequently asked questions.
- What this calculator does not do — the honest list.
There are also pages on how the project is put together, for anyone reading the source rather than using the calculator.
- The f64 boundary — how values cross between JavaScript and Rust.
- Build output — what wasm-pack emits and how the browser loads it.
- Testing — why there are two test suites.
- Build from source — exact commands for a clean clone.
Questions and answers
Is the Rust WASM Calculator free to use?
Yes. The calculator is free, requires no account, and its full source code is published under the pigfox/rust-wasm-calc repository on GitHub.
Does this calculator send my calculations to a server?
No. The WebAssembly module is downloaded once and every calculation runs inside your browser tab. There is no calculation API and no request is made when you press a button.
What operations does the calculator support?
Addition, subtraction, multiplication, division, square root, squaring, and factorial, plus a four-function memory register and a list of the five most recent calculations. The WebAssembly module additionally exports percentage and compound interest functions that have no keypad button.
Why is the arithmetic written in Rust instead of JavaScript?
So that error cases are enforced by the compiler. Division and square root return a Rust Result type, and factorial uses checked multiplication, so overflow and domain errors surface as explicit errors rather than as NaN or a silently wrapped number.
🦀 Rust WASM Calculator