Math Helpers
Helpers for cost curves, progress bars, and min/max/clamp — the calculations idle and incremental games reach for constantly. All of them work without converting through double, and stay overflow-free even for values beyond the 8 unit slots.
Cost-Curve Math
Log10, Pow, and Sqrt compute in log space, so they stay precise even for very large values.
Useful for upgrade cost curves of the form baseCost * growthRate^level:
Buy-Max Count
AffordableCount solves the geometric-series price curve (baseCost * growthRate^n) for how many items a given balance can afford. Use it to implement a "buy max" button.
growthRatemust be greater than 1.baseCostmust be greater than 0.- Returns
0ifbalanceis less thanbaseCost.
Progress
ToProgress returns the current value's progress toward max as an overflow-free float between 0 and 1. It's a pure function safe to call every frame, for health bars, experience bars, and similar UI.
Min / Max / Clamp
Increment / Decrement Operators
As with subtraction, a decrement that would go negative clamps to zero.