From 4dbc139ede2a711410c4e23b19c7896361126bd2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 1 Mar 2026 22:57:23 -1000 Subject: [PATCH] [core] Use ternary in fast_div1000_32 for clarity --- esphome/core/helpers.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 2218c17a49..8a55359840 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -553,11 +553,8 @@ inline ESPHOME_ALWAYS_INLINE uint32_t fast_div1000_32(uint64_t us) { uint32_t hi = static_cast(us >> 32); // Combine remainder term: hi * (2^32 % 1000) + lo uint32_t adj = hi * R + lo; - if (adj < lo) { - // Overflow: the true value is 2^32 + adj, so apply the identity again - return hi * Q + (adj + R) / D + Q; - } - return hi * Q + adj / D; + // If adj overflowed, the true value is 2^32 + adj; apply the identity again + return hi * Q + (adj < lo ? (adj + R) / D + Q : adj / D); } /// Return a random 32-bit unsigned integer.