Skip to main content

Module bignum

Module bignum 

Source
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; uses log10(a + b) = log10(a) + log10(1 + 10^(b - a)) for a >= b.
  • try_sub: same trick. Returns None if the result would be negative.
  • cmp: direct comparison of the log values.
  • to_f64: useful at display sites (for the legacy format::big path) and inside formulas that need a real f64 (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 finite log10.