Expand description
Mag — a non-negative real represented as log10(value).
The whole point: gameplay-side quantities (cuques, FPS, tree multipliers,
per-fingerer modifier mults) compound multiplicatively across thousands
of bought nodes and powerup catches. Stored as f64, the product
reaches Infinity after a long-haul session — the headline bug from
the wild “broken save” triage. Stored as log10, the same product
fits comfortably inside an f64 for any value the player could
conceivably observe; the dynamic range is 10^(±1.8e308), i.e.
“truly infinite” for any practical gameplay.
§Representation
Mag { log10: f64 }, where log10 is the base-10 logarithm of the
value. Zero is the sentinel log10 == f64::NEG_INFINITY; everything
else is finite. Negatives are not representable (the only place the
game produced one was an underflow that signalled a bug anyway —
try_sub returns Option, callers handle the deficit explicitly).
§Operations
mul/div: addition / subtraction in log space — cheap.add: requires un-logging the smaller addend; useslog10(a + b) = log10(a) + log10(1 + 10^(b - a))fora >= b.try_sub: same trick. ReturnsNoneif the result would be negative.cmp: direct comparison of the log values.to_f64: useful at display sites (for the legacyformat::bigpath) and inside formulas that need a realf64(e.g. RNG range bounds, multiplier caps from the procgen).
Structs§
- Mag
- Non-negative log-magnitude.
Mag::ZERO == Mag { log10: -inf },Mag::ONE == Mag { log10: 0.0 }. All other instances carry a finitelog10.