Evaluate
The /evaluate endpoint safely evaluates a mathematical expression and returns its result. It uses a Pratt parser — no eval() is ever called.
How it works?
Expressions are tokenized then parsed recursively using binding powers (Pratt parsing). The result is computed directly from the AST — no eval(), no Function(). Two constants are available: pi (≈ 3.14159…) and e (≈ 2.71828…). Recursion depth is capped at 100 and expression length at 500 characters.
curl -X GET \ "https://api.moxon.dev/v6/evaluate"Send the request to see the response here.
exprstringrequiredThe mathematical expression to evaluate (max 500 characters)
precisionnumberoptionalNumber of decimal places in the result (0–15)
| Operator | Description |
|---|---|
+ | Addition |
- | Subtraction / unary negation |
* | Multiplication |
/ | Division |
% | Modulo |
^ | Exponentiation |
Unary - binds looser than ^, matching standard math convention: -2^2 evaluates to -4 (i.e. -(2^2)), not 4.
sin, cos, tan, asin, acos, atan, sqrt, abs, floor, ceil, round, log, log2, log10
exprstringThe original expression
resultnumberThe evaluated result
If parameters are missing or invalid, the API will return an error:
- 400
Please provide a math expression (?expr={expression})Theexprparameter is missing - 400
Expression is too long (max 500 characters)The expression exceeds 500 characters - 400
Maximum expression depth exceededNesting depth exceeds 100 levels - 400
Division by zeroThe expression attempts to divide by zero - 400
Unknown identifier: {name}An unknown constant or function name was used - 400
Invalid number: {num}A number literal has more than one decimal point (e.g.1.2.3) - 400
precision must be between 0 and 15Theprecisionvalue is out of range
Last updated on September 12, 2026