[sensor] Replace powf with pow10_int in sensor filters

Add shared pow10_int() helper to helpers.h that computes 10^exp
using iterative multiplication/division instead of powf.

Replace powf(10, exp) calls in:
- sensor/filter.cpp: ValueListFilter and RoundFilter
- helpers.cpp: normalize_accuracy_decimals (refactored to use
  pow10_int for the general case, keeping -1/-2 fast paths)

Eliminates powf/__ieee754_powf from builds where sensor filters
are the only remaining powf call site.
This commit is contained in:
J. Nick Koston
2026-02-19 15:28:12 -06:00
parent d2b7d40716
commit 6a8844e2fc
3 changed files with 25 additions and 14 deletions
+7 -12
View File
@@ -468,20 +468,15 @@ 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) {
// Clamp to -9 to keep divisor within uint32_t range (max 10^9 = 1,000,000,000)
int8_t dec = accuracy_decimals < -9 ? (int8_t) -9 : accuracy_decimals;
uint32_t divisor;
if (dec == -1) {
divisor = 10;
} else if (dec == -2) {
divisor = 100;
float divisor;
if (accuracy_decimals == -1) {
divisor = 10.0f;
} else if (accuracy_decimals == -2) {
divisor = 100.0f;
} else {
divisor = 1000;
for (int8_t i = dec + 3; i < 0; i++)
divisor *= 10;
divisor = pow10_int(-accuracy_decimals);
}
auto divisor_f = static_cast<float>(divisor);
value = roundf(value / divisor_f) * divisor_f;
value = roundf(value / divisor) * divisor;
accuracy_decimals = 0;
}
}