You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generated DTO comparers treat equal floating-point values as different (NearlyEqual not negated) #426
Equals returns false exactly when the values are nearly equal, and true when they differ. So ComparerProvider.Resolve(literal).Equals(literal, copy) is false for a LiteralRational and an identical copy of it.
Cause
SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs:845-862 emits all four floating-point branches without !:
double, nullable and not nullable (lines 845 and 849);
float, nullable and not nullable (lines 859 and 862).
The float branch also has two more slips:
The non-nullable line is emitted after the nullable one even for a nullable float, because there is no else.
It compares with DefaultDoubleEpsilon instead of DefaultFloatEpsilon.
Impact
Today the only generated comparer with a real-valued property is LiteralRationalComparer (LiteralRational::value : Real). Every comparison of two LiteralRationals is inverted on value.
Fix
Negate the four checks, add the else to the float branch, and use DefaultFloatEpsilon there. Then regenerate the comparers. A unit test that compares a LiteralRational with a copy of itself, and with one whose value differs, catches it.
How it was found
The Flexo integration scenario of #407 (step 4, KerML Kernel) reads a LiteralRational with value = 2.5 back from the server. It reports "differs from what was sent", although the value read back is equal.
Activity