analyze
Evaluate an expression and display its full parse tree with each sub-result's value, pinpointing where rounding or precision loss occurs.
Instructions
Evaluate an expression and return its AST as an indented tree of sub-results.
Same arguments and evaluation as calculate — mode (fixed-point default,
floating-point, rational) and min_fixed_point_precision behave identically —
but instead of one final value this returns the WHOLE parse tree, each node
annotated with the Value it computed in that mode. Reach for it to see WHERE a
surprising answer comes from: which sub-expression rounded, overflowed, or lost
precision, rather than only the rounded result.
tree is a multi-line string, one node per line, indented by depth (root last-
applied operator at the top, literals at the leaves). Each line is
<OPCODE/LITERAL "lexeme"> Value = <value> (<type>[<scale>], <exact|inexact>)
followed by ·-separated per-mode details: the value in hex (fixed-point as
M@D with whole-byte digits, @<scale> dropped at scale 0; float as raw IEEE-754
bits), or a rational's decimal approximation. The <scale> is the fixed-point
decimal scale (omitted for modes without one). For example (1 + 1/2) * 3 in
fixed-point:
BINARY_MUL Value = 3 (fixed-point[0], inexact) · hex 0x03
BINARY_ADD Value = 1 (fixed-point[0], inexact) · hex 0x01
LITERAL "1" Value = 1 (fixed-point[0], exact) · hex 0x01
BINARY_DIV Value = 0 (fixed-point[0], inexact) · hex 0x00
LITERAL "1" Value = 1 (fixed-point[0], exact) · hex 0x01
LITERAL "2" Value = 2 (fixed-point[0], exact) · hex 0x02
LITERAL "3" Value = 3 (fixed-point[0], exact) · hex 0x03— the 1/2 = 0 leaf (inexact, scale 0) makes plain that fixed-point rounded the
half away, so the product is 3, not 4.5, and every node above it inherits the
inexactness. (Raise min_fixed_point_precision, or use a different mode, to keep
those digits.)
On success tree is the rendering and error is null; on a bad mode, an invalid
min_fixed_point_precision, or a malformed/erroring expression, tree is null and
error carries the message (the same messages calculate returns).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | ||
| mode | No | fixed-point | |
| min_fixed_point_precision | No |