Skip to main content

CalculationResult

@forge/monorepo


@forge/monorepo / backend/src / CalculationResult

Type Alias: CalculationResult

CalculationResult = { expression: string; ok: true; value: number; } | { expression: string; ok: false; reason: string; }

Defined in: backend/src/toolkit/compute.ts:20

Evaluate an arithmetic expression, without eval.

eval on a string a model produced is remote code execution with extra steps, and new Function is the same thing wearing a hat. So this is a small recursive-descent parser over a closed grammar: numbers, + - * / % ^, parentheses, unary minus, and a fixed set of named functions and constants. Anything else is a syntax error rather than a silent success.

Precision is IEEE-754 double, like every other number in this runtime. It is not a decimal library, and 0.1 + 0.2 is documented rather than hidden, because a tool that quietly rounds is a tool that disagrees with the spreadsheet the person is comparing it against.