S2198 — Unnecessary mathematical comparisons should not be made

Language
C#
Type
Code smell
Severity
Critical
Tags
suspicious

Why is this an issue?

Certain mathematical comparisons will always return the same value, and should not be performed.

Specifically, the following comparisons will return either always true or always false depending on the kind of comparison:

Noncompliant code example


float f = 42.0f;
if (f <= double.MaxValue) { } // Noncompliant: always true
if (f > double.MaxValue) { }  // Noncompliant: always false

Resources

Documentation

↑ Back to top