CruxDevCruxDev Tools Prompts
dev Utility • Zero-Server Privacy • 100% Client-Side

Math Expression Evaluator

Evaluate mathematical expressions with variables, functions (sin, cos, log, sqrt), constants (π, e), and unit conversions.

Overview

Evaluate a mathematical expression and get the result instantly as you type. The evaluator understands common functions like sqrt, sin, and log, the constants pi and e, and exponentiation with the caret symbol, all computed locally with standard JavaScript math.

How It Works

Type an expression in the input field and the result updates on every change, shown large in a result card you can click to copy. Preset buttons load examples such as 2^10, sqrt(144) + 5, sin(pi/4), and log(1000) so you can see the supported syntax at a glance. Invalid expressions show the underlying error message instead of a result, and there is no button to press: evaluation is continuous.

Step-by-Step Usage Guide

  1. Type or paste an expression into the input field.
  2. Read the result in the large green output card.
  3. Click the result card to copy the value.
  4. Use a preset button to load a ready-made example expression.

Technical Specifications & Standards

The evaluator works by translating recognized names into their JavaScript Math equivalents and then compiling the expression as a JavaScript function. Supported functions are sin, cos, tan, sqrt, cbrt, log (mapped to base-10 log10), ln (natural log), abs, floor, and ceil, plus the constants pi and e; the caret symbol is rewritten to the power operator. Trigonometric functions use radians, so sin(pi/4) is about 0.7071. Two consequences follow from the design. First, the full JavaScript expression grammar is available: parentheses, ternaries, and even bitwise operators work, not just a fixed math grammar. Second, it is not a sandboxed parser: whatever you type is evaluated as JavaScript in the page. That is safe for your own use because everything stays in your browser and nothing is sent anywhere, but do not treat it as a security boundary, and do not paste expressions from untrusted sources. Inverse trigonometric functions and min, max, round, and exp are not in the name list, so they fail with an error rather than silently misbehaving.

Targeted Use Cases

  • Quickly checking a formula while programming, without opening a desktop calculator.
  • Converting between log bases using the log for base-10 and ln for natural log distinction.
  • Verifying trigonometry for graphics or game code, where radians are the norm.
  • Computing powers and roots with caret and sqrt for quick estimates.

Notes & Gotchas

  • Use radians for trigonometric arguments; wrap degrees in a multiplication by pi divided by 180.
  • Remember log is log10 here and ln is the natural logarithm, the opposite of some calculators.
  • Wrap arguments in parentheses so sqrt(16) * sin(pi / 2) parses the way you expect.
  • Do not paste untrusted expressions: the evaluator runs them as JavaScript in the page.

Frequently Asked Questions

Is log base 10 or base e?

In this tool log is base 10, and ln is the natural logarithm. So log(1000) evaluates to 3 and ln(e) evaluates to 1.

Can I use variables or define my own functions?

No. The input is evaluated as a single JavaScript expression with no variable bindings, so any undefined name raises an error. Write constants inline instead.

Why does the caret produce exponentiation?

The evaluator rewrites the caret to JavaScript's power operator before evaluating. Note that this means bitwise XOR, which the caret means in raw JavaScript, is not available here.

Is it safe to paste expressions from elsewhere?

Treat it like running a snippet: the expression is evaluated as JavaScript in your browser. Nothing is uploaded, but avoid executing expressions from sources you do not trust.