calculate_expression
Evaluate an arithmetic expression exactly: + - * / // % ** use rational numbers, not floats, so 0.1 + 0.2 = 0.3, and money strings like "$1,200.50" read as numbers. Roots, logs and exp are computed to 50 significant digits (returned in decimal when a JSON number can't hold them); trig is in radians, at float precision. Use this instead of doing math in your head; use calculate_date for anything with dates or times, and run_op("stats") to summarize a column of data. Pure computation: no network, same answer every time. Unknown names, syntax errors and results over 5,000 digits are refused with a suggested fix. Example: expr="price * qty * (1 + tax/100)", vars={"price": "$19.99", "qty": 3, "tax": 8.25}, places=2 gives 64.92.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expr | Yes | Python-style arithmetic; ** is power (^ is refused). Functions: pct(p, x) = p% of x, pct_change(old, new) = (new - old) / old * 100, round(x, places) half-up, floor, ceil, int, abs, sqrt, exp, ln, log(x) natural or log(x, base), log10, log2, pow, factorial, gcd, lcm, comb(n, k), perm(n, k), sin, cos, tan, asin, acos, atan, atan2(y, x), sum, mean, median, min, max. Constants: pi, e, tau, true, false. | |
| vars | No | Values for the names used in expr: numbers or numeric strings like "$1,200.50". Any name in expr must be here. | |
| places | No | Round the result to this many decimals, half-up. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exact | No | Every digit of an integer too large for a JSON number. | |
| value | Yes | The result: a number, or true/false for comparisons. | |
| decimal | No | Up to 50 significant digits, when value (a JSON number) holds fewer. | |
| fraction | No | The exact fraction of a repeating decimal, like 1/3. |