Math Expression Evaluator
runs in your browserA notepad calculator: one expression per line, variables that carry down, units, complex numbers, matrices and symbolic derivatives — math.js, in your browser.
One expression per line. Variables and functions carry down the page; ans is the previous result; # starts a comment.
Expressions
Results
Results appear here, one per line.
Quick reference
arithmetic
2^10, 10!, 17 mod 5power, factorial, remainder0xff, 0b1010, 0o17hex, binary, octal1.5e6, 3 + 4iexponent, complex5 & 3, 5 | 3, 1 << 4bitwise
functions
sqrt, cbrt, nthRoot(27, 3)rootslog(x), log(x, 2), log10, explogarithmssin(30 deg), asin, atan2trigonometry, radians by defaultround(x, 2), floor, ceil, absroundinggcd, lcm, isPrime, combinations(5, 2)integersmean, median, std, sum([1, 2, 3])statistics
units
5 cm to inchconvert2 hours + 30 minutesadd compatible units (min is the function)60 mph to m/scompound units20 degC to degFtemperatures
algebra
a = 3assign; a is available belowf(x) = x^2 + 1define a functionsimplify("2x + 3x")symbolic simplificationderivative("x^2", "x")symbolic derivative
about this tool
A page, not a keypad
This is a notepad calculator: each line is an expression, the result appears
beside it, and everything defined higher up is available lower down. Write
radius = 4.5 cm, then area = pi * radius^2, then area to inch^2, and
the three answers sit in a column you can copy as text. ans is always the
previous result, as on a hand calculator; # starts a comment; a semicolon
at the end of a statement silences its output, so a = 1; b = 2; sets both
quietly. A line that fails shows its error in place and the lines after it
carry on, so one typo does not blank the page.
The engine is math.js, which arrives when you first
focus the input rather than with the page, since it is a quarter of a
megabyte. It gives the page real numeric range: complex numbers (sqrt(-9)
is 3i), matrices and determinants, statistics over lists, bitwise
operators, hex, binary and octal literals, a few hundred functions, and
symbolic algebra — derivative("x^3 + 2x", "x") returns 3 * x ^ 2 + 2 and
simplify("2x + 3x") returns 5 * x.
Units
Quantities carry their units through the arithmetic: 5 km / (12 minutes) to km/h is 25 km / h, 2 hours + 30 minutes is 2.5 hours, 20 degC to degF is 68 degF, and adding metres to seconds is refused with Units do
not match. Trigonometry is in radians unless you say otherwise, so write
sin(30 deg). One trap is worth knowing: min is the minimum function, not
a minute, so 30 min multiplies thirty by a function and fails; write
30 minutes. Everything else takes its usual abbreviation.
Numbers
Arithmetic is ordinary double-precision floating point, so results are exact
to about fifteen digits and factorials past 170! overflow to Infinity. The
display rounds to 14 significant digits — enough to hide the representation
error that makes 0.1 + 0.2 print as 0.30000000000000004 elsewhere, and
too few to hide any digit you typed. Values of 10¹⁵ and above, or below
10⁻⁹, switch to exponent notation.
Limits
There is no percent suffix: in math.js % is modulo, so 17 % 5 is 2;
write price * 0.18, or use the percentage calculator. Evaluation runs on the
page's own thread, so an expression that builds something enormous —
range(1, 1e8), say — will freeze the tab until the browser gives up on it.
The import function is disabled so that a pasted page cannot redefine the
engine; createUnit still works if you need a unit math.js lacks. Variables
live only in the page: reloading starts with a blank sheet, and nothing is
stored.
For loan and percentage arithmetic with the terms laid out, use the percentage & EMI calculator. For values that carry units, the unit converter keeps them straight.
questions
- What can I type?
- Ordinary arithmetic with + − * / ^ and brackets, factorials (10!), hex, binary and octal literals (0xff, 0b1010, 0o17), complex numbers (3 + 4i), units (5 cm to inch, 60 mph to m/s), matrices ([1, 2; 3, 4]), assignments (a = 3), function definitions (f(x) = x^2) and a few hundred functions: sqrt, log, sin, round, gcd, mean, det, derivative, simplify and more.
- Why is 30 min an error?
- Because min is the minimum function in math.js, so 30 min reads as thirty times a function. Write 30 minutes (or 30 minute). Most other units accept their usual abbreviations: cm, kg, mph, kWh, degC.
- How does ans work?
- ans always holds the result of the previous line that produced a value, exactly as on a hand calculator. Assignments update it too, comments and errors do not.
- Why does 0.1 + 0.2 show 0.3 here but 0.30000000000000004 in JavaScript?
- The arithmetic is the same binary floating point; the display rounds to 14 significant digits, which hides the representation error without hiding any digit you meant to type. Results with more than 15 digits switch to exponent notation.
- Are percentages supported?
- Not as a suffix: in math.js the % sign is the modulo operator, so 17 % 5 is 2. Write percentages as fractions (price * 0.18) or use the Percentage & EMI calculator, which handles discounts, changes and prices before tax by name.