Calculator and expression evaluator

Work out an arithmetic expression safely: brackets, powers, functions such as sqrt and log, and variables.

Input

The expression to work out.
Optional named numbers to use in the expression, as an object.

Result

Fill in the input and press Run.

Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.

Use it from code or an agent

curl -s https://setget.net/v1/tools/math-eval \
  -H 'Content-Type: application/json' \
  -d '{"input":{"expression":"(2 + 3) * 4 ** 2 / sqrt(16)"}}'
import json, urllib.request

body = {'input': {'expression': '(2 + 3) * 4 ** 2 / sqrt(16)'}}
request = urllib.request.Request("https://setget.net/v1/tools/math-eval", json.dumps(body).encode(),
                                 {"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/math-eval", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({"input":{"expression":"(2 + 3) * 4 ** 2 / sqrt(16)"}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
  "slug": "math-eval",
  "input": {
    "expression": "(2 + 3) * 4 ** 2 / sqrt(16)"
  }
}
{
  "input": {
    "expression": "(2 + 3) * 4 ** 2 / sqrt(16)"
  }
}

Endpoint: POST /v1/tools/math-eval. Over MCP: run_tool with slug: "math-eval". Machine-readable: input schema, Markdown. Connect an agent.

Inputs

NameTypeRequiredWhat it does
expression string yes The expression to work out.
variables json no Optional named numbers to use in the expression, as an object.

Examples

Input
{
  "expression": "(2 + 3) * 4 ** 2 / sqrt(16)"
}
Result
{
  "result": 20,
  "text": "20",
  "type": "integer"
}

With variables

Input
{
  "expression": "sqrt(x**2 + y**2)",
  "variables": {
    "x": 3,
    "y": 4
  }
}
Result
{
  "result": 5,
  "text": "5",
  "type": "integer"
}

A very large whole number

Input
{
  "expression": "2**100"
}
Result
{
  "result": "1267650600228229401496703205376",
  "text": "1267650600228229401496703205376",
  "type": "integer"
}

Decimals without noise

Input
{
  "expression": "0.1 + 0.2"
}
Result
{
  "result": 0.3,
  "text": "0.3",
  "type": "number"
}

Questions

What does ^ mean?
A power, the same as **. So 2^10 is 1024.
Why is a big answer returned as text?
Whole numbers above 9,007,199,254,740,992 cannot be held exactly by many programs, so "result" is text for those and no digits are lost.
Do the trigonometry functions use degrees or radians?
Radians. Write sin(radians(30)) for 30 degrees. Because pi cannot be stored exactly, sin(pi) gives a tiny number close to 0 instead of exactly 0.
What are the limits?
Expressions up to 1,000 characters, whole numbers up to about 10,000 digits, factorial up to 3,000, and decimal results rounded to 12 significant digits.
Is it safe?
Yes. The expression is parsed and only arithmetic is allowed. No code is ever run.