2023-05-03 11:06:20 +02:00
== Why is this an issue?
2023-06-16 15:37:20 +02:00
Certain https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/comparison-operators[mathematical comparisons] will always return the same value, and should not be performed.
2023-02-15 15:00:19 +01:00
2023-06-16 15:37:20 +02:00
Specifically, the following comparisons will return either always `true` or always `false` depending on the kind of comparison:
2023-02-15 15:00:19 +01:00
2023-06-16 15:37:20 +02:00
* comparing a `char` with a numeric constant that is outside of the range of `char`
* comparing a `float` with a numeric constant that is outside of the range of `float`
* comparing a `long` with a numeric constant that is outside of the range of `long`
* comparing a `ulong` with a numeric constant that is outside of the range of `ulong`
* etc.
2023-02-15 15:00:19 +01:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2023-02-15 15:00:19 +01:00
2023-05-25 14:18:12 +02:00
[source,csharp]
2023-02-15 15:00:19 +01:00
----
float f = 42.0f;
2023-06-16 15:37:20 +02:00
if (f <= double.MaxValue) { } // Noncompliant: always true
if (f > double.MaxValue) { } // Noncompliant: always false
2023-02-15 15:00:19 +01:00
----
2023-06-16 15:37:20 +02:00
include::../resources.adoc[]
2023-06-22 10:38:01 +02:00
2023-06-16 15:37:20 +02:00
include::../rspecator.adoc[]