mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Clarify stats range
Current update formula ensures that the possible value range is [-32 * D, 32 * D]. So we never overflow if abs(32 * D) < INT16_MAX Thanks to Joost and mstembera to clarify this. No functional change.
This commit is contained in:
parent
01d97521fd
commit
9c35b9365d
1 changed files with 2 additions and 6 deletions
|
@ -38,12 +38,8 @@ struct StatBoards : public std::array<std::array<T, Size2>, Size1> {
|
||||||
|
|
||||||
void update(T& entry, int bonus, const int D) {
|
void update(T& entry, int bonus, const int D) {
|
||||||
|
|
||||||
assert([&]{
|
assert(abs(bonus) <= D); // Ensure range is [-32 * D, 32 * D]
|
||||||
int v = entry + bonus * 32 - entry * abs(bonus) / D;
|
assert(abs(32 * D) < INT16_MAX); // Ensure we don't overflow
|
||||||
return INT16_MIN < v && v < INT16_MAX;
|
|
||||||
}());
|
|
||||||
|
|
||||||
assert(abs(bonus) <= D); // Consistency check for below formula
|
|
||||||
|
|
||||||
entry += bonus * 32 - entry * abs(bonus) / D;
|
entry += bonus * 32 - entry * abs(bonus) / D;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue