From 9c35b9365d75a3522cee47536419534b1de91f48 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Fri, 18 Aug 2017 02:02:35 -0700 Subject: [PATCH] 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. --- src/movepick.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/movepick.h b/src/movepick.h index d6451f6b..db0ba3c4 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -38,12 +38,8 @@ struct StatBoards : public std::array, Size1> { void update(T& entry, int bonus, const int D) { - assert([&]{ - int v = entry + bonus * 32 - entry * abs(bonus) / D; - return INT16_MIN < v && v < INT16_MAX; - }()); - - assert(abs(bonus) <= D); // Consistency check for below formula + assert(abs(bonus) <= D); // Ensure range is [-32 * D, 32 * D] + assert(abs(32 * D) < INT16_MAX); // Ensure we don't overflow entry += bonus * 32 - entry * abs(bonus) / D; -- 2.39.2