Scientific calculator

A full scientific calculator with trig, logs, powers, roots, factorials and memory — running entirely in your browser.

DEG
0

Tip: you can type on your keyboard too. Use Enter for equals, Backspace to delete and Esc to clear.

A scientific calculator that does the maths the safe way

This calculator handles everything a classroom or workbench scientific calculator does — the four basic operators, parentheses, percentages, powers and roots, the three core trigonometric functions, natural and base-10 logarithms, factorials, the constants π and e, and a four-key memory. What makes it different is what happens under the hood: it never calls JavaScript’s eval(). Instead it ships a small, purpose-built math engine, so your expression is treated as data to be measured, not code to be run.

How the math engine works

Every time you press =, your expression travels through three stages:

  1. Tokenize. The raw string is scanned left to right and broken into tokens: numbers, operators (+ - * / ^ %), function names (sin, ln, …) and parentheses.
  2. Shunting-yard. Edsger Dijkstra’s algorithm reorders those tokens from ordinary infix notation into Reverse Polish Notation (RPN), using an operator stack so that precedence (* before +) and parentheses are honoured. The rule is simple: while the operator on top of the stack has greater or equal precedence, pop it to the output, then push the new operator.
  3. Evaluate. The RPN is run through a stack machine. Numbers are pushed; an operator pops the right number of operands, computes, and pushes the result. The single value left on the stack is the answer.

A worked example: 2 + 3 × 4

Tokenizing gives 2, +, 3, *, 4. Because * binds tighter than +, the shunting-yard step produces the RPN 2 3 4 * +. The stack machine then pushes 2, 3 and 4; the * pops 3 and 4 to compute 3 × 4 = 12, leaving 2 and 12; finally + computes 2 + 12 = 14. Wrapping the start in parentheses, (2 + 3) × 4, reorders the RPN to 2 3 + 4 * and the result becomes 20 — exactly the difference parentheses are supposed to make.

Functions and what they return

KeyMeaningExample
sin / cos / tanTrigonometry (DEG or RAD)sin(30) = 0.5 in DEG
lnNatural log (base e)ln(e) = 1
logCommon log (base 10)log(1000) = 3
Square rootsqrt(16) = 4
x^yPower2^10 = 1024
x!Factorial5! = 120
1/xReciprocal1/x of 4 = 0.25
Privacy note: there is no server and no logging of what you calculate. The tokenizer, parser and evaluator all run on your device, and because eval() is never used, your input can never be executed as code. Close the tab and nothing remains.

Frequently asked questions

Does this scientific calculator work offline and keep my calculations private?

Yes. Every calculation is parsed and evaluated entirely in your browser with a custom math engine — there is no server round-trip, no analytics on what you type and nothing is stored. Once the page has loaded you can keep using it offline, and closing the tab erases your history.

How does the calculator evaluate an expression without using eval()?

It uses a classic three-stage pipeline. A tokenizer splits your input into numbers, operators and function names; the shunting-yard algorithm reorders those tokens into Reverse Polish Notation (RPN) so precedence and parentheses are respected; then a small stack machine evaluates the RPN. This avoids JavaScript eval() entirely, so no arbitrary code can run.

What is the difference between DEG and RAD mode?

It controls how the trig functions interpret angles. In DEG mode, sin(30) treats 30 as degrees and returns 0.5. In RAD mode the same input is read as 30 radians. Switch modes with the DEG/RAD toggle before entering a trig function. Inverse results and constants like π are unaffected.

How do the memory keys (MC, MR, M+, M-) work?

M+ adds the current result to a stored memory value, M- subtracts it, MR recalls the stored value into the display, and MC clears the memory back to zero. A small "M" indicator lights up whenever memory holds a non-zero number.

Why do I sometimes see "Error"?

The calculator shows "Error" when an expression cannot be evaluated — for example dividing by zero, taking the square root or logarithm of a negative number, an unbalanced parenthesis, or a factorial of a negative or non-integer value. Press AC to reset and start again.

How precise are the results?

Calculations use JavaScript double-precision floating-point (about 15–16 significant digits). Results are rounded for display and tiny rounding artefacts near zero are cleaned up, so sin(180) in DEG reads as 0 rather than a number like 1.2e-16.