Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioaversa committed Jan 27, 2023
1 parent 9b9275b commit b2b0fa0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ private static void CheckEquality(SonarSyntaxNodeReportingContext context)
}
}

// Only checks for type and member accessed. No need to check that proposedMethod exists in type because:
// - both special members and corresponding `IsXXX()` methods exist in double and float since .NET 1.1
// - both special members and corresponding `IsXXX()` methods exist in Half since its introduction, in .NET 5
// - while NFloat has been introduced in .NET 6, special members and corresponding IsXXX() methods have been introduced at the same time, in .NET 7
// - no other floating point typeswith prevision issues exist before .NET 7, and any new type after has to conform to `IFloatingPointIeee754`
private static string ProposedMessageForMemberAccess(SonarSyntaxNodeReportingContext context, ExpressionSyntax expression) =>
expression is MemberAccessExpressionSyntax memberAccess
&& SpecialMembers.TryGetValue(memberAccess.GetName(), out var proposedMethod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

public class EqualityOnFloatingPoint
{
bool HalfEqual(Half first, Half second)
=> first == second; // Noncompliant {{Do not check floating point equality with exact values, use a range instead.}}
// ^^
bool HalfEqual(Half first, Half second) =>
first == second; // Noncompliant {{Do not check floating point equality with exact values, use a range instead.}}
// ^^

bool NFloatEqual(NFloat first, NFloat second)
=> first == second; // Noncompliant
bool NFloatEqual(NFloat first, NFloat second) =>
first == second; // Noncompliant

bool IsEpsilon<T>(T value) where T : IFloatingPointIeee754<T>
=> value == T.Epsilon; // Noncompliant
bool IsEpsilon<T>(T value) where T : IFloatingPointIeee754<T> =>
value == T.Epsilon; // Noncompliant

bool IsPi<T>(T value) where T : IFloatingPointIeee754<T>
=> value <= T.Pi && ((value >= T.Pi)); // Noncompliant
bool IsPi<T>(T value) where T : IFloatingPointIeee754<T> =>
value <= T.Pi && ((value >= T.Pi)); // Noncompliant

bool IsNotE<T>(T value) where T : IFloatingPointIeee754<T>
=> value > T.E || ((value < T.E)); // Noncompliant
bool IsNotE<T>(T value) where T : IFloatingPointIeee754<T> =>
value > T.E || ((value < T.E)); // Noncompliant

bool AreEqual<T>(T first, T second) where T : IFloatingPointIeee754<T>
=> first == second; // Noncompliant
bool AreEqual<T>(T first, T second) where T : IFloatingPointIeee754<T> =>
first == second; // Noncompliant

bool Equal<T>(T first, T second) where T : IBinaryFloatingPointIeee754<T>
=> first == second; // Noncompliant
bool Equal<T>(T first, T second) where T : IBinaryFloatingPointIeee754<T> =>
first == second; // Noncompliant
}

public class ReportSpecificMessage_NaN
Expand Down

0 comments on commit b2b0fa0

Please sign in to comment.