From 2bb077cb1f7509df3b1ec3a99ec74cc1708bd9f2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 19 Feb 2026 12:10:51 -0600 Subject: [PATCH] [core] Replace powf with integer math in normalize_accuracy_decimals Replace powf(10.0f, accuracy_decimals) with integer divisor computation to avoid pulling in __ieee754_powf (~2.2KB) on builds where this is the only powf call site. Tested on ESP8266 with web_server: -3.1KB flash, -16 bytes RAM. --- esphome/core/helpers.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index 09e755ca71..dc93ff331e 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -468,8 +468,18 @@ ParseOnOffState parse_on_off(const char *str, const char *on, const char *off) { static inline void normalize_accuracy_decimals(float &value, int8_t &accuracy_decimals) { if (accuracy_decimals < 0) { - auto multiplier = powf(10.0f, accuracy_decimals); - value = roundf(value * multiplier) / multiplier; + uint32_t divisor; + if (accuracy_decimals == -1) { + divisor = 10; + } else if (accuracy_decimals == -2) { + divisor = 100; + } else { + divisor = 1000; + for (int8_t i = accuracy_decimals + 3; i < 0; i++) + divisor *= 10; + } + auto divisor_f = static_cast(divisor); + value = roundf(value / divisor_f) * divisor_f; accuracy_decimals = 0; } }