Skip to main content

Module arith

Module arith 

Source
Expand description

Arithmetic expression evaluation (is/2, comparisons).

Ported byte-for-byte from patch-prolog v1’s builtins.rs (eval_arith plus the arith_* helpers). Semantics — floored mod, truncating //, float-yielding /, checked i64 overflow, NaN/Infinity rejection, and the exact zero-divisor labels — match v1 so error message text is identical (verified against the v1 oracle; see unit tests).

NOTE on the immediate-integer range: cell INT is a 61-bit immediate but eval computes in full i64. A result that fits i64 yet overflows the i61 immediate cannot be boxed until M4; for M3 the is/2 ABI reports it as an error (see pred::plg_rt_b_is). Evaluation itself never narrows — it always works in i64.

Enums§

ArithValue
An evaluated arithmetic value: integer or float (mirrors v1 ArithVal).

Functions§

arith_eq
arith_gt
arith_lt
eval
Evaluate expr (a heap word) to an arithmetic value. On Err(()), m.error is already populated with v1-identical message text. The unit error type is intentional: the rich error lives in m.error (the M3 ABI contract), so callers only need to know success vs failure.