CalcDuck

Scientific Calculator

Scientific Calculator

Supports + - * / ^ %, parentheses, unary minus, ! (factorial), sin cos tan asin acos atan ln log sqrt abs exp, and the constants pi and e.
Result
8.5
Parsed as
(sin(30) + (2 ^ 3))

This calculator evaluates a typed math expression using standard order of operations: parentheses first, then exponents (right to left), then multiplication/division, then addition/subtraction. For example, 2+3*4 evaluates to 14, and 2^3^2 evaluates to 512 because exponents apply right to left (2^(3^2), not (2^3)^2). Trig functions like sin(30) use whichever angle mode you select.

Tip: “Copy with settings” shares a link that opens this calculator with your numbers already filled in.

How this calculator works

Type a math expression using standard notation and this calculator parses and evaluates it, showing both the numeric result and the expression as it was understood (fully parenthesized, so you can confirm the order of operations was applied the way you expected). It supports the four basic operations, exponents, percent/modulo, parentheses, unary minus, factorial, common trig and inverse trig functions, natural and base-10 logarithms, square root, absolute value, exponential, and the constants pi and e.

Expressions are parsed with a dedicated recursive-descent parser, not evaluated with JavaScript's eval() or Function()—the input is tokenized, turned into a syntax tree following standard precedence rules, and only then computed function by function. Malformed input (an unmatched parenthesis, an unrecognized function name, dividing by zero, or a value outside a function's valid domain) produces a specific error message instead of a crash or a silently wrong answer.

Order of operations and supported syntax

Precedence, highest to lowest: parentheses and functions, then factorial (!), then exponent (^, right-associative), then unary minus, then multiply/divide/modulo (* / %), then add/subtract (+ -)Functions require parentheses: sin(x) cos(x) tan(x) asin(x) acos(x) atan(x) ln(x) log(x) sqrt(x) abs(x) exp(x)Constants: pi = 3.14159..., e = 2.71828...

sin, cos, tan, asin, acos, and atan use the angle mode you select (degrees or radians); ln is the natural log, log is base 10.

Worked example: sin(30) + 2^3 * (4 - 1), degree mode

  1. Parentheses first: (4 - 1) = 3.
  2. Exponent next: 2^3 = 8.
  3. Multiplication: 8 * 3 = 24.
  4. sin(30) in degree mode = 0.5, so the final sum is 0.5 + 24 = 24.5.

Frequently asked questions

Why does 2^3^2 equal 512 and not 64?

Exponentiation is right-associative in standard mathematical notation, so 2^3^2 means 2^(3^2) = 2^9 = 512, not (2^3)^2 = 64. This calculator follows that convention, matching graphing calculators and most programming languages that support the ^ operator this way.

Do I need parentheses around a function's argument?

Yes—write sin(30), not sin 30. Requiring parentheses keeps the grammar unambiguous, especially for nested calls like sin(asin(0.5)).

What happens with degrees versus radians?

The angle mode setting controls every trig and inverse-trig function. sin(30) is 0.5 in degree mode but about -0.988 in radian mode, since 30 radians is a very different angle than 30 degrees. Set the mode to match how your input angles are expressed.

What if I enter something invalid, like 5/0 or an unmatched parenthesis?

You'll see a specific error message—"Division by zero", "Unbalanced parentheses", "Unknown function or constant", or a domain error like "sqrt is only defined for non-negative arguments"—instead of a crash or a wrong number.

Is eval() or the Function constructor used to evaluate my input?

No. The expression is tokenized and parsed into a syntax tree by a purpose-built parser, then evaluated node by node. This avoids the security and correctness risks of running arbitrary code through JavaScript's eval.

Sources

Related calculators