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_truthyand the VM’sValue::is_truthy. Falsy:false, numeric zero (-0.0is 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
LogosIntmaterialization, so the value lives in a register and LLVM’s induction reasoning survives); overflow raises the same loud canonical error thelogos_*_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’smath.isclosesemantics: relative tolerance 1e-9 (nine significant digits agree) with absolute floor 1e-12 (so values near zero compare sanely), plus an exact fast path soinf is approximately infholds. 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.
Noneifffis NaN. - logos_
div_ exact - Truncating division — loud canonical panic on a zero divisor (the same
failure the interpreter raises);
i64::MIN / -1promotes exactly. - logos_
div_ i64 checked_divisNoneon 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 / -1cannot occur (chain operands are width-bounded far belowi128::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 toBigInt). Distinct fromlogos_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
Floatused to index anInt-keyed map matches the Int keyiiff the float is exactlyi(integral and in i64 range) — the compiled mirror of the interpreter’s1 == 1.0key 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 digitsLogosIntwould. - logos_
pow_ exact - Exact integer exponentiation — the i64 fast path promotes to
BigInton 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 % -1is 0 (no overflow, no panic). - logos_
rem_ i64 checked_remisNoneon a zero divisor (canonical panic via the exact helper) and oni64::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)).