areClose(), isClose()

This commit is contained in:
Pavel Kirienko
2014-08-28 20:25:27 +04:00
parent f255a725c1
commit 9d806c2be6
5 changed files with 148 additions and 9 deletions
@@ -107,13 +107,15 @@ struct UAVCAN_EXPORT ${t.cpp_type_name}
#endif
}
/**
* Comparison operators are based on @ref uavcan::areClose(),
* which allows to safely compare floating point values.
*/
bool operator==(ParameterType rhs) const;
bool operator!=(ParameterType rhs) const { return !operator==(rhs); }
/**
* This comparison is based on @ref uavcan::areClose(), which ensures proper comparison of
* floating point fields at any depth.
*/
bool isClose(ParameterType rhs) const;
static int encode(ParameterType self, ::uavcan::ScalarCodec& codec,
::uavcan::TailArrayOptimizationMode tao_mode = ::uavcan::TailArrayOptEnabled);
@@ -182,6 +184,20 @@ UAVCAN_PACKED_END
template <int _tmpl>
bool ${scope_prefix}<_tmpl>::operator==(ParameterType rhs) const
{
% if fields:
return
% for idx,a in enumerate(fields):
${a.name} == rhs.${a.name}${' &&' if (idx + 1) < len(fields) else ';'}
% endfor
% else:
(void)rhs;
return true;
% endif
}
template <int _tmpl>
bool ${scope_prefix}<_tmpl>::isClose(ParameterType rhs) const
{
% if fields:
return