diff --git a/libraries/AP_Param/AP_Param.cpp b/libraries/AP_Param/AP_Param.cpp index 9bd7cf83a0..2ac444eef5 100644 --- a/libraries/AP_Param/AP_Param.cpp +++ b/libraries/AP_Param/AP_Param.cpp @@ -735,7 +735,7 @@ bool AP_Param::save(bool force_save) } else { v2 = get_default_value(&info->def_value); } - if (v1 == v2 && !force_save) { + if (AP_Math::is_equal(v1,v2) && !force_save) { return true; } if (phdr.type != AP_PARAM_INT32 && @@ -1177,7 +1177,7 @@ void AP_Param::convert_old_parameter(const struct ConversionInfo *info) } else if (ptype <= AP_PARAM_FLOAT && header.type <= AP_PARAM_FLOAT) { // perform scalar->scalar conversion float v = ap->cast_to_float((enum ap_var_type)header.type); - if (v != ap2->cast_to_float(ptype)) { + if (!AP_Math::is_equal(v,ap2->cast_to_float(ptype))) { // the value needs to change set_value(ptype, ap2, v); ap2->save(); diff --git a/libraries/AP_Param/AP_Param.h b/libraries/AP_Param/AP_Param.h index 1cdf96e4d3..67eee6414f 100644 --- a/libraries/AP_Param/AP_Param.h +++ b/libraries/AP_Param/AP_Param.h @@ -25,6 +25,8 @@ #include #include #include +#include +#include "float.h" #include #include <../StorageManager/StorageManager.h> @@ -421,7 +423,7 @@ public: /// Combined set and save /// bool set_and_save(const T &v) { - bool force = (_value != v); + bool force = fabsf(_value - v) < FLT_EPSILON; set(v); return save(force); }