Expand description
$(( )) — checked 64-bit integer arithmetic and another-base number
reading.
Three stages, kept separate so each can be tested on its own:
tokenize (text → Tok), parse (Tok → ArithExpr), and
evaluation (eval_sync for a scope with no $(...) reachable, and
Kernel::eval_arith_async in kernel.rs for the general case).
Supports: decimal/hex/base#digits literals (base 2..=36), the full C
precedence table down through ?:, $name/${...}/$(...)/nested
$((...)) as operands, and bare (( expr )) as a condition (see
Stmt::Arith/Expr::Arith in ast/types.rs).
Diverges from bash on purpose: overflow is an error, never a wrap; a
leading-zero numeral is refused, never read as octal; an unset or empty
operand is an error, never 0; $(...) on the unselected side of
&&/||/?: never runs.
Structs§
- Arith
Error - An error from tokenizing, parsing, or evaluating
$(( )).messageis the full, final text shown to the caller;spanis the byte range in the arithmetic source the error concerns, when one exists (evaluation errors over already-resolved values carry0..0— the message already names the values).
Functions§
- eval_
arithmetic - Tokenize, parse, and evaluate
text(the content of$(( ))) with no$(...)support — the fast path used where an async evaluator isn’t available. A reachable$(...)errors loudly rather than silently resolving to nothing.