Skip to main content

Module formula

Module formula 

Expand description

The formula language of the demo’s custom landscape (D94).

A formula is an expression in x and y: decimal numbers, the constants pi and e, + - * / ^ (** is an alias of ^), parentheses, implicit multiplication (2x, 3(x + 1), x y), and the functions in FUNCTIONS. The typographic forms the page prints (−, ×, ·, ÷, π, ², ³) are accepted too. ^ binds tighter than a leading minus, so -x^2 is -(x^2), and it is right-associative.

Formula::parse compiles the source to a postfix program whose stack depth is known statically, so Formula::evaluate runs without allocating or recursing. Source length, nesting depth, and stack depth are capped, so a hostile query string cannot exhaust the page.

Structs§

Formula
A compiled formula in x and y.
ParseError
Why a source is not a formula.

Constants§

FUNCTIONS
The functions a formula may call, with their argument counts.
MAX_LEN
The longest accepted source, in bytes.
MAX_NESTING
The deepest accepted nesting of parentheses, function calls, and signs.