Skip to content

Fix comparison operators for double values in DS #9735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 23, 2019
2 changes: 1 addition & 1 deletion src/Engine/ProtoCore/DSASM/Stack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static bool CompareStackValues(StackValue sv1, StackValue sv2, RuntimeCor

if(Double.IsInfinity(value1) && Double.IsInfinity(value2))
return true;
return MathUtils.Equals(value1, value2);
return sv1.Equals(sv2);
case AddressType.Boolean:
return sv1.BooleanValue == sv2.BooleanValue;
case AddressType.ArrayPointer:
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/ProtoCore/Lang/BuiltInFunctionEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2593,7 +2593,7 @@ bool Equals(StackValue sv1, StackValue sv2)
var v1 = sv1.IsDouble ? sv1.DoubleValue: sv1.IntegerValue;
var v2 = sv2.IsDouble ? sv2.DoubleValue: sv2.IntegerValue;

return MathUtils.Equals(v1, v2);
return sv1.Equals(sv2);
}

public int Compare(StackValue sv1, StackValue sv2)
Expand Down
4 changes: 1 addition & 3 deletions src/Engine/ProtoCore/Utils/MathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace ProtoCore.Utils
{
public static class MathUtils
{
public static double Tolerance = 1e-5;

public static bool IsLessThan(double lhs, double rhs)
{
return (lhs < rhs) && !Equals(lhs, rhs);
Expand All @@ -28,7 +26,7 @@ public static bool IsLessThanOrEquals(double lhs, double rhs)

public static bool Equals(double lhs, double rhs)
{
return Math.Abs(lhs - rhs) < Tolerance;
return lhs.Equals(rhs);
}
}
}