curatedapi

Expression calculator

Evaluate an arithmetic expression exactly, with functions like sqrt, ln, sin and factorial.

The expression. Operators: + - * / ^ (or **) and ! (factorial); constants pi and e; functions: abs, acos, asin, atan, cbrt, ceil, cos, cosh, exp, factorial, floor, ln, log, log10, log2, max, min, mod, root, sin, sinh, sqrt, tan, tanh. At most 1000 characters.
Unit for trig function inputs and inverse-trig outputs. Options: radians: radians; degrees: degrees
More options: rounding and decimals
Precision and rounding
Rounding mode applied once to each result. Default half_even.
Round results to this many digits after the decimal point.
Round results to this many significant digits.

Examples

Result: Unary minus and powers

Result
The value of the expression.
-4 exact
Interpretation
The expression as parsed, with explicit parentheses.
-(2 ^ 2)

Rounding: Half even, 20 significant digits. Calculator math/expression@1.

How it is calculated

Standard operator precedence: ^ (right-associative) > unary minus > * / > + -

Evaluates expressions such as (1/3 + 1/6) * 2^10 or sqrt(2) * sin(45) with no floating-point error: rational arithmetic is exact, and irrational results (roots, logarithms, trig) are computed with certified interval arithmetic and rounded correctly. The interpretation output shows how the expression was read, with every implied parenthesis written out.

  • Implicit multiplication (2pi, 3(4)) is not accepted; write 2*pi.
  • log(x) alone is ambiguous between ln and log10, so it needs a base: log(x, 10).
  • Results must be below 1e100 in magnitude; smaller than 1e-100 is reported as 0.

References

Results follow each calculator's documented rules and the sources listed. They are not financial, tax or legal advice. Check that the rules fit your case before you rely on a result. See the terms.

Use it from your code

POST /v1/calc/math/expressionVersion 1
curl https://api.curatedapi.com/v1/calc/math/expression \
  -H "Authorization: Bearer $CURATEDAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "expression": "-2^2"
  }'
The same call in Python
import os

import requests

payload = {
    "expression": "-2^2",
}
response = requests.post(
    "https://api.curatedapi.com/v1/calc/math/expression",
    headers={"Authorization": f"Bearer {os.environ['CURATEDAPI_KEY']}"},
    json=payload,
    timeout=10,
)
print(response.json()["result"])
The same call in JavaScript
const payload = {
    "expression": "-2^2",
};
const response = await fetch("https://api.curatedapi.com/v1/calc/math/expression", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.CURATEDAPI_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
});
console.log((await response.json()).result);

MCP tool calc_math_expression at https://mcp.curatedapi.com. Inputs, outputs and errors in the API reference.

Put it on your website

<div data-curatedapi-widget="math/expression" data-key="capi_public_…"></div>
<script src="https://widgets.curatedapi.com/v1/widget.js" async></script>

Use a public key registered for your site. Calculations are billed like API calls. How widgets work.

Related calculators

Add this calculator to your website

Paste two lines into your page and your visitors get this calculator. Each use counts as one call on your plan, the same as the API.

Free for up to 1,000 uses a month. 50,000 uses a month cost $9.00 on the Starter plan.