Skip to main content

Module ops

Module ops 

Source
Expand description

Exact numeric comparison for GENERATED code.

Mixed Int/Float comparison in LOGOS is EXACT — mathematical values, never a lossy cast (i as f64 rounds above 2^53, so a cast-based == would call 9007199254740993 equal to the float 9007199254740992.0). The AOT backend emits these helpers for statically-mixed compares; same-type compares are untouched, so hot loops pay nothing.

Traits§

Truthy
Truthiness for GENERATED code — ONE definition shared with the interpreter’s RuntimeValue::is_truthy and the VM’s Value::is_truthy. Falsy: false, numeric zero (-0.0 is zero; NaN is nonzero and truthy), nothing (None), and empty Text/Seq/Map/Set. Everything else is truthy.

Functions§

logos_add_exact
Exact Int arithmetic for GENERATED code (overflow ruling v2, stage 2): the i64 fast path is a single checked op; overflow spills to the promoting crate::types::LogosInt — the AOT’s mirror of the interpreter’s Int→BigInt promotion. impl Into<LogosInt> lets an already-promoted operand chain through the same helper unchanged.
logos_add_i64
Fused NARROWED exact ops (overflow ruling v2, stage 2): emitted when a single exact op’s result narrows straight back to i64 — the dominant hot-loop shape. The fast path is one checked op on machine integers (no LogosInt materialization, so the value lives in a register and LLVM’s induction reasoning survives); overflow raises the same loud canonical error the logos_*_exact(..).expect_i64("Int") chain raises, byte for byte (the printed value is the exact result).
logos_approx_eq
a is approximately b — the TOLERANT float comparison (== is IEEE bit-exact). Python’s math.isclose semantics: relative tolerance 1e-9 (nine significant digits agree) with absolute floor 1e-12 (so values near zero compare sanely), plus an exact fast path so inf is approximately inf holds. NaN is approximately nothing. ONE definition — the tree-walker, VM, JIT deopt path, AOT, and WASM lowering all share it.
logos_cmp_i64_f64
Exact comparison of an i64 against an f64. None iff f is NaN.
logos_div_exact
Truncating division — loud canonical panic on a zero divisor (the same failure the interpreter raises); i64::MIN / -1 promotes exactly.
logos_div_i64
checked_div is None on exactly the two slow cases (zero divisor, i64::MIN / -1); both re-route through the exact helper for the canonical error / exact-promotion narrow.
logos_div_i128
Truncating i128 division inside a width-bounded exact chain. The zero divisor raises the canonical error; i128::MIN / -1 cannot occur (chain operands are width-bounded far below i128::MIN).
logos_floordiv_exact
Floor division — the quotient rounded toward NEGATIVE INFINITY (-7 // 2 → -4), the // operator. Loud canonical panic on a zero divisor; exact (promotes to BigInt). Distinct from logos_div_exact, which truncates toward zero.
logos_i64_eq_f64
i == f, exactly (NaN is equal to nothing).
logos_i64_key_of_f64
Numeric-unified map key: a Float used to index an Int-keyed map matches the Int key i iff the float is exactly i (integral and in i64 range) — the compiled mirror of the interpreter’s 1 == 1.0 key coercion. A non-integral float (1.5) matches no Int key.
logos_mul_exact
logos_mul_i64
logos_narrow_i128
Narrow a width-bounded i128 chain result back to i64 (overflow ruling v2, stage 2): the codegen lowers an exact chain whose worst-case bit-width provably fits i128 as native i128 arithmetic (every intermediate exact by construction) and narrows ONCE at the root. Same canonical error text as expect_i64 — an i128 prints the same digits LogosInt would.
logos_pow_exact
Exact integer exponentiation — the i64 fast path promotes to BigInt on overflow (2 ** 100). Loud canonical panic on a negative exponent (an Int can’t hold the fractional result), mirroring the interpreter.
logos_rem_exact
Truncating remainder — loud canonical panic on a zero divisor; i64::MIN % -1 is 0 (no overflow, no panic).
logos_rem_i64
checked_rem is None on a zero divisor (canonical panic via the exact helper) and on i64::MIN % -1 (which the helper resolves to 0 — cold but correct).
logos_rem_i128
Truncating i128 remainder inside a width-bounded exact chain — the canonical zero-divisor error, sign of the dividend.
logos_sub_exact
logos_sub_i64
logos_truthy
The truthiness entry point the AOT backend emits (logos_truthy(&x)).