[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.
This commit is contained in:
J. Nick Koston
2026-02-19 12:10:51 -06:00
parent bd50b80882
commit 2bb077cb1f

View File

@@ -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<float>(divisor);
value = roundf(value / divisor_f) * divisor_f;
accuracy_decimals = 0;
}
}