Skip to content
UniKit

Math expression evaluator

A hand-written expression evaluator: arithmetic, power, parentheses, unary minus, pi/e/tau constants, 20+ functions, factorials, percentages, degree/radian switching and multi-line variable assignments with per-line results and error positions.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Angle unit

Supports + - * / % ^, parentheses, unary minus, the constants pi / e / tau, the functions abs ceil floor round sqrt cbrt exp ln log log2 log10 sin cos tan asin acos atan atan2 pow min max sign, factorials n! and percentages.

`10 % 3` is modulo while `50%` is a percentage: % counts as modulo when a number, variable or "(" follows it. Assign variables on their own line (a = 5) and reuse them later.

Result

Type an expression to see the result of every line

What this tool does

  • Evaluate a whole sheet of formulas at once: arithmetic, modulo, powers, parentheses, unary minus, the constants pi / e / tau and 20+ functions such as sqrt, log and the trigonometric family.
  • Work through multi-step calculations: assign variables on one line (a = 5) and reuse them later, which suits unit conversions, invoice splitting or deriving a loan formula step by step.
  • Go beyond a pocket calculator: factorials (n!), percentages (50% = 0.5) and a degree/radian switch are all built in, so trigonometry does not need manual conversion.
  • Debug expressions: errors report the exact line and column plus the reason, whether that is an unclosed parenthesis, a mistyped function name or the wrong argument count.

Example

Input

a = 5
b = 12
sqrt(a^2 + b^2)
sin(pi/6)
5!

Output

a = 5 = 5
b = 12 = 12
sqrt(a^2 + b^2) = 13
sin(pi/6) = 0.5
5! = 120

The angle unit defaults to radians, so sin(pi/6) is 0.5. Switch to degrees and the same line becomes about 0.0087.

Frequently asked questions

Is 50% a percentage or a modulo?

Both tokens exist. A % followed by a number, variable or "(" is modulo, anything else is a percent sign. So 10 % 3 gives 1 while 50% gives 0.5 and 5 + 10% gives 5.1.

Why is sin(30) not 0.5?

The default angle unit is radians, so sin(30) evaluates 30 radians. Switch the unit to degrees, or write sin(pi/6) in radian mode, to get 0.5.

A line failed — are the remaining lines still evaluated?

No. Evaluation stops at the first failing statement. The message tells you the line and column plus the reason, for example division by zero, an unknown function, an unclosed parenthesis or a factorial outside 0–170.

What can I name a variable, and may I use pi or sqrt?

Names start with a letter or underscore and are case-insensitive (they are lowercased internally). Assigning to a constant (pi / e / tau) or a function name is rejected with "cannot assign to a constant or function name".

Is my input uploaded anywhere?

No. The evaluator is a self-contained JavaScript module — its own tokenizer and recursive-descent parser — running locally. No request is made, it works offline, and expressions are never logged.

Keywords:数学表达式求值calculator计算器math evaluator函数表达式阶乘百分号变量赋值

Related tools