Math Expression Calculator - Evaluate Formulas Online
Evaluate mathematical expressions with trigonometric, logarithmic functions, variables, and unit conversions. 100% client-side — no data sent to server.
No variables defined
Define variables like: x = 5
No history yet
Supported Expressions
Arithmetic Operators
| Syntax | Example | Result |
|---|---|---|
| + | 5 | |
| - | 6 | |
| * | 12 | |
| / | 3.333... | |
| ^ | 1024 | |
| % | 1 | |
| ! | 120 | |
| () | 20 |
Trigonometric Functions
| Syntax | Example | Result |
|---|---|---|
| sin(x) | 1 | |
| cos(x) | 1 | |
| tan(x) | 1 | |
| asin(x) | 1.5708... | |
| acos(x) | 1.5708... | |
| atan(x) | 0.7854... | |
| atan2(y, x) | 0.7854... |
Logarithmic & Exponential
| Syntax | Example | Result |
|---|---|---|
| log(x) | 1 | |
| log10(x) | 3 | |
| log2(x) | 10 | |
| log(x, base) | 3 | |
| exp(x) | 2.7183... |
Roots & Powers
| Syntax | Example | Result |
|---|---|---|
| sqrt(x) | 12 | |
| cbrt(x) | 3 | |
| pow(x, y) | 256 | |
| nthRoot(x, n) | 2 | |
| abs(x) | 5 |
Rounding & Sign
| Syntax | Example | Result |
|---|---|---|
| round(x) | 4 | |
| round(x, n) | 3.14 | |
| ceil(x) | 4 | |
| floor(x) | 3 | |
| fix(x) | -3 | |
| sign(x) | -1 |
Statistics
| Syntax | Example | Result |
|---|---|---|
| min(a, b, ...) | 1 | |
| max(a, b, ...) | 4 | |
| mean(a, b, ...) | 4 | |
| median(a, b, ...) | 3 |
Combinatorics
| Syntax | Example | Result |
|---|---|---|
| factorial(n) | 120 | |
| n! | 3628800 | |
| combinations(n, k) | 10 | |
| permutations(n, k) | 20 | |
| gamma(x) | 24 |
Constants
| Syntax | Example | Result |
|---|---|---|
| pi | 3.1416... | |
| e | 2.7183... | |
| phi | 1.6180... | |
| tau | 6.2832... | |
| Infinity | Infinity |
Number Formats
| Syntax | Example | Result |
|---|---|---|
| 0x (hex) | 255 | |
| 0b (binary) | 10 | |
| 0o (octal) | 63 | |
| 1.5e3 (scientific) | 1500 |
Unit Conversions
| Syntax | Example | Result |
|---|---|---|
| value unit to unit | 12.7 cm | |
| length | 1.6093 km | |
| mass | 220.46 lb | |
| temperature | 22.222 degC | |
| time | 60 minutes | |
| data | 1000 MB |
Variables & Comments
| Syntax | Example | Result |
|---|---|---|
| x = value | (assigns 5) | |
| use variable | 10 | |
| # comment | (no output) | |
| expr; | (suppressed) |
Frequently Asked Questions
What is a math expression calculator?
A math expression calculator is an online tool that evaluates mathematical expressions written as text. Instead of clicking buttons on a traditional calculator, you type expressions like sin(pi/4) * 2 + sqrt(9), 2^10, or log(100) and get instant results. It understands operator precedence, parentheses, functions, and constants — essentially acting as a programmable scientific calculator that accepts natural mathematical notation.
How do I use this math expression calculator?
Type any mathematical expression into the input field and the result appears instantly below. You can use arithmetic operators (+, -, *, /, ^, %), functions like sin(), cos(), log(), sqrt(), and constants like pi and e. For more complex calculations, define variables (e.g., x = 5) on one line and use them on the next (e.g., x^2 + 3). You can also convert units by typing expressions like 5 inch to cm.
Is my data safe? Does anything get sent to a server?
All expression evaluation is performed 100% in your browser using the math.js JavaScript library. No data — including your expressions, variables, or results — is transmitted to any server. The tool uses a safe mathematical parser (not JavaScript eval()), so there is no risk of code injection. Your calculations never leave your device.
What mathematical functions are supported?
The calculator supports a comprehensive set of functions: trigonometric (sin, cos, tan, asin, acos, atan), logarithmic (log for natural log, log10 for base 10, log2 for base 2), roots and powers (sqrt, cbrt, pow, exp), rounding (ceil, floor, round, abs), factorial (5!), and more. You can also use constants like pi, e, and phi (golden ratio).
Can I use hexadecimal, binary, or octal numbers?
Yes. You can input numbers in different bases using standard prefixes: hexadecimal with 0x (e.g., 0xFF = 255), binary with 0b (e.g., 0b1010 = 10), and octal with 0o (e.g., 0o77 = 63). You can mix these in expressions: 0xFF + 0b1010 evaluates to 265.
How do unit conversions work?
Type a value with its unit followed by "to" and the target unit. For example: 5 inch to cm returns 12.7 cm, 100 kg to lb returns approximately 220.462 lb, and 72 fahrenheit to celsius returns approximately 22.222 celsius. You can also combine unit conversions with math: (5 inch + 3 cm) to mm calculates the sum and converts to millimeters.
Can I define and use variables?
Yes. Assign a value to a variable name using the = operator: radius = 10. Then use that variable in subsequent expressions: pi * radius^2 returns the area of a circle. Variables persist throughout your session, and you can see all defined variables in the Variables panel. Use the Clear All button to reset all variables.
Code Examples
// Math expression evaluation using math.js
import { evaluate, format } from "mathjs";
// Basic arithmetic
console.log(evaluate("2 + 3 * 4")); // 14
console.log(evaluate("(2 + 3) * 4")); // 20
console.log(evaluate("2 ^ 10")); // 1024
// Trigonometric functions
console.log(evaluate("sin(pi / 4)")); // 0.7071067811865476
console.log(evaluate("cos(0)")); // 1
// Logarithmic functions
console.log(evaluate("log10(100)")); // 2
console.log(evaluate("log(e)")); // 1
console.log(evaluate("log2(1024)")); // 10
// Variables
const scope = {};
evaluate("x = 5", scope);
evaluate("y = 10", scope);
console.log(evaluate("sqrt(x^2 + y^2)", scope)); // 11.180339887498949
// Unit conversions
console.log(evaluate("5 inch to cm").toString()); // 12.7 cm
console.log(evaluate("100 kg to lb").toString()); // ~220.462 lb