# Calculator and expression evaluator

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

- Endpoint: `POST https://setget.net/v1/tools/math-eval` with JSON `{"input": {...}}`
- MCP: `run_tool` with `slug` = `math-eval`
- Page: https://setget.net/tools/math-eval

## Inputs

- `expression` (required, string): The expression to work out.
- `variables` (optional, json): Optional named numbers to use in the expression, as an object.

## Example 1

```json
{"input":{"expression":"(2 + 3) * 4 ** 2 / sqrt(16)"}}
```

Result:

```json
{"result":20,"text":"20","type":"integer"}
```

## Example 2: With variables

```json
{"input":{"expression":"sqrt(x**2 + y**2)","variables":{"x":3,"y":4}}}
```

Result:

```json
{"result":5,"text":"5","type":"integer"}
```

## Example 3: A very large whole number

```json
{"input":{"expression":"2**100"}}
```

Result:

```json
{"result":"1267650600228229401496703205376","text":"1267650600228229401496703205376","type":"integer"}
```

## Example 4: Decimals without noise

```json
{"input":{"expression":"0.1 + 0.2"}}
```

Result:

```json
{"result":0.3,"text":"0.3","type":"number"}
```

**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.
