fix: handle Inf and NaN correctly in is_within_tolerance
While reviewing the parameter comparison logic, I noticed that is_within_tolerance(float('inf'), float('inf')) returns False instead of True.
The reason is IEEE 754 arithmetic: Inf - Inf = NaN abs(NaN) = NaN NaN <= anything = False
This means when a parameter value is Inf on both the FC and in the config file, the function wrongly reports them as different values. The result is unnecessary parameter re-uploads to the flight controller.
The function is used in 10 places across 4 files, so this affects parameter comparison, upload decisions, and change detection.
Fix by adding a non-finite check at the start of the function:
- If either value is Inf or NaN, use direct equality (x == y)
- This correctly handles Inf==Inf (True), -Inf==-Inf (True), Inf!=-Inf (False), NaN!=NaN (False)
- math_isfinite was already imported in this module
Checklist
- [x] Verified by a human programmer
- [x] Code follows our coding standards
- [x] No breaking changes or properly documented
Testing
- [x] Unit tests pass
Added two regression tests to tests/test_data_model_par_dict.py:
- test_is_within_tolerance_inf_values
- test_is_within_tolerance_nan_values
All tests pass locally (Python 3.12.10, pytest-9.0.3)