Expression evaluation API
Evaluate an arithmetic expression exactly, with functions like sqrt, ln, sin and factorial.
POST https://api.curatedapi.com/v1/calc/math/expression
- Version 1
- MCP tool
calc_math_expression - Try it in the browser
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.
Formula
Standard operator precedence: ^ (right-associative) > unary minus > * / > + -
- 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.
Inputs
Send numbers as strings to keep every digit. options sets precision and rounding (see numbers and rounding).
| Input | Type | Description |
|---|---|---|
expression required |
string | 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. |
angle_unit |
radians | degrees default radians |
Unit for trig function inputs and inverse-trig outputs. Options: radians: radians; degrees: degrees |
options.rounding |
half_even | half_up | half_down | up | down | ceiling | floor | Rounding mode applied once to each result. Default half_even. |
options.decimals |
integer | Round results to this many digits after the decimal point. |
options.significant_digits |
integer | Round results to this many significant digits. |
Result
Under result in the answer, next to exactness, precision, inputs, formula, references and warnings.
| Result | Type | Description |
|---|---|---|
result | decimal (string) | The value of the expression. |
interpretation | string | The expression as parsed, with explicit parentheses. |
Examples
No floating-point error
curl https://api.curatedapi.com/v1/calc/math/expression \
-H "Authorization: Bearer $CURATEDAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"expression": "0.1 + 0.2"
}'
{
"calculator": "math/expression@1",
"result": {
"result": "0.3",
"interpretation": "0.1 + 0.2"
},
"exactness": {
"result": "exact"
},
"precision": {
"rounding": "half_even",
"significant_digits": 20
},
"inputs": {
"expression": "0.1 + 0.2",
"angle_unit": "radians"
},
"formula": "Standard operator precedence: ^ (right-associative) > unary minus > * / > + -",
"references": [
{
"title": "Order of operations",
"url": "https://en.wikipedia.org/wiki/Order_of_operations"
},
{
"title": "A. Ziv, Fast evaluation of elementary mathematical functions with correctly rounded last bit, ACM TOMS 17(3), 1991 (rounding with growing precision)",
"url": "https://dblp.org/pid/53/3586"
}
],
"warnings": []
}
Exact fractions
curl https://api.curatedapi.com/v1/calc/math/expression \
-H "Authorization: Bearer $CURATEDAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"expression": "(1/3 + 1/6) * 2^10"
}'
{
"calculator": "math/expression@1",
"result": {
"result": "512",
"interpretation": "((1 / 3) + (1 / 6)) * (2 ^ 10)"
},
"exactness": {
"result": "exact"
},
"precision": {
"rounding": "half_even",
"significant_digits": 20
},
"inputs": {
"expression": "(1/3 + 1/6) * 2^10",
"angle_unit": "radians"
},
"formula": "Standard operator precedence: ^ (right-associative) > unary minus > * / > + -",
"references": [
{
"title": "Order of operations",
"url": "https://en.wikipedia.org/wiki/Order_of_operations"
},
{
"title": "A. Ziv, Fast evaluation of elementary mathematical functions with correctly rounded last bit, ACM TOMS 17(3), 1991 (rounding with growing precision)",
"url": "https://dblp.org/pid/53/3586"
}
],
"warnings": []
}
Unary minus and powers
curl https://api.curatedapi.com/v1/calc/math/expression \
-H "Authorization: Bearer $CURATEDAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"expression": "-2^2"
}'
{
"calculator": "math/expression@1",
"result": {
"result": "-4",
"interpretation": "-(2 ^ 2)"
},
"exactness": {
"result": "exact"
},
"precision": {
"rounding": "half_even",
"significant_digits": 20
},
"inputs": {
"expression": "-2^2",
"angle_unit": "radians"
},
"formula": "Standard operator precedence: ^ (right-associative) > unary minus > * / > + -",
"references": [
{
"title": "Order of operations",
"url": "https://en.wikipedia.org/wiki/Order_of_operations"
},
{
"title": "A. Ziv, Fast evaluation of elementary mathematical functions with correctly rounded last bit, ACM TOMS 17(3), 1991 (rounding with growing precision)",
"url": "https://dblp.org/pid/53/3586"
}
],
"warnings": []
}
Trig in degrees
curl https://api.curatedapi.com/v1/calc/math/expression \
-H "Authorization: Bearer $CURATEDAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"expression": "sin(30)",
"angle_unit": "degrees"
}'
{
"calculator": "math/expression@1",
"result": {
"result": "0.5",
"interpretation": "sin(30)"
},
"exactness": {
"result": "exact"
},
"precision": {
"rounding": "half_even",
"significant_digits": 20
},
"inputs": {
"expression": "sin(30)",
"angle_unit": "degrees"
},
"formula": "Standard operator precedence: ^ (right-associative) > unary minus > * / > + -",
"references": [
{
"title": "Order of operations",
"url": "https://en.wikipedia.org/wiki/Order_of_operations"
},
{
"title": "A. Ziv, Fast evaluation of elementary mathematical functions with correctly rounded last bit, ACM TOMS 17(3), 1991 (rounding with growing precision)",
"url": "https://dblp.org/pid/53/3586"
}
],
"warnings": []
}
References
- Order of operations
- A. Ziv, Fast evaluation of elementary mathematical functions with correctly rounded last bit, ACM TOMS 17(3), 1991 (rounding with growing precision)
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.
Errors share one format; see errors. Billing, retries and batches work the same for every endpoint.