Oh MyUtils

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.

Precision
Examples
Expression
Result
Enter an expression to see the result

No variables defined
Define variables like: x = 5

No history yet

Supported Expressions

Arithmetic Operators

SyntaxExampleResult
+5
-6
*12
/3.333...
^1024
%1
!120
()20

Trigonometric Functions

SyntaxExampleResult
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

SyntaxExampleResult
log(x)1
log10(x)3
log2(x)10
log(x, base)3
exp(x)2.7183...

Roots & Powers

SyntaxExampleResult
sqrt(x)12
cbrt(x)3
pow(x, y)256
nthRoot(x, n)2
abs(x)5

Rounding & Sign

SyntaxExampleResult
round(x)4
round(x, n)3.14
ceil(x)4
floor(x)3
fix(x)-3
sign(x)-1

Statistics

SyntaxExampleResult
min(a, b, ...)1
max(a, b, ...)4
mean(a, b, ...)4
median(a, b, ...)3

Combinatorics

SyntaxExampleResult
factorial(n)120
n!3628800
combinations(n, k)10
permutations(n, k)20
gamma(x)24

Constants

SyntaxExampleResult
pi3.1416...
e2.7183...
phi1.6180...
tau6.2832...
InfinityInfinity

Number Formats

SyntaxExampleResult
0x (hex)255
0b (binary)10
0o (octal)63
1.5e3 (scientific)1500

Unit Conversions

SyntaxExampleResult
value unit to unit12.7 cm
length1.6093 km
mass220.46 lb
temperature22.222 degC
time60 minutes
data1000 MB

Variables & Comments

SyntaxExampleResult
x = value(assigns 5)
use variable10
# 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

Related Tools