CALC Expression
CALC evaluates ACE's numeric arithmetic grammar.
Syntax
Spaces inside the CALC body are removed before the numeric parser runs.
Operators and precedence
From highest to lowest precedence, the production parser handles:
| Operator | Meaning |
|---|---|
(...) |
Parentheses |
unary !, unary +, unary - |
ACE numeric NOT, positive sign, negative sign |
^ |
Power / exponent (std::pow) |
*, /, % |
Multiplication, division, floating-point remainder (fmod) |
+, - |
Addition, subtraction |
The three unary prefix operators share the same precedence and are parsed recursively. Unary ! uses the same numeric transformation documented for NOT.
This precedence is ACE's actual parser behavior; in particular, unary operators bind before ^.
Repeated ^ operators are processed left to right by the current parser. For example, CALC{2^3^2} evaluates as (2^3)^2, which is 64.
Numeric literals
The current CALC number parser consumes decimal digits and . characters. Exponent/scientific notation such as 1e3 is not part of this parser's numeric-literal grammar. ACE's own numeric-result formatter deliberately avoids feeding scientific notation back into nested CALC expressions for this reason.
Examples
These forms are already exercised by ACE's expression tests and existing reference material:
Results:
Nested ACE expressions are resolved before the surrounding CALC is completed.
CALC's production wrapper catches exceptions from its internal numeric parser and returns 0 in that case. Do not use a result of 0 by itself as proof that an input expression was syntactically valid, because 0 is also a legitimate calculation result.