From 7b19bbf75f7a58479f30d547b2cf6992635307c8 Mon Sep 17 00:00:00 2001 From: Balduin Date: Tue, 7 Jul 2026 13:15:39 +0200 Subject: [PATCH] refactor(timesync): swap exp -> expf to save flash This is the only double-precision exp in the codebase, and occupies a hefty chunk of flash. Relevant history: - https://github.com/PX4/PX4-Autopilot/pull/9365 / 39bb65ffd7 - Timesync algorithm is initially added with this "sigmoid" function calculated completely in float - but _filter_alpha / _filter_beta are double, presumably to be compatible with adjusting _time_offset in add_sample which is a double (which it needs to be to represent large offsets coming from int64_t) - https://github.com/PX4/PX4-Autopilot/pull/9809 / cf74166801 - to silence warnings, the expf is swapped for an exp and the entire sigmoid calculation is now in double I would say the better fix to silence the promotion warning is to keep the sigmoid function in float (precision not needed) and cast to double right after, to not accidentally change anything depending on double. --- src/lib/timesync/Timesync.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/timesync/Timesync.cpp b/src/lib/timesync/Timesync.cpp index 078c60d2494..9d8d798f619 100644 --- a/src/lib/timesync/Timesync.cpp +++ b/src/lib/timesync/Timesync.cpp @@ -76,8 +76,8 @@ void Timesync::update(const uint64_t now_us, const int64_t remote_timestamp_ns, // Filter gain scheduling if (!sync_converged()) { // Interpolate with a sigmoid function - double progress = (double)_sequence / (double)CONVERGENCE_WINDOW; - double p = 1.0 - exp(0.5 * (1.0 - 1.0 / (1.0 - progress))); + const float progress = (float) _sequence / (float) CONVERGENCE_WINDOW; + double p = (double)(1.f - expf(0.5f * (1.f - 1.f / (1.f - progress)))); _filter_alpha = p * ALPHA_GAIN_FINAL + (1.0 - p) * ALPHA_GAIN_INITIAL; _filter_beta = p * BETA_GAIN_FINAL + (1.0 - p) * BETA_GAIN_INITIAL;