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
pavel-mikula-sonarsource
changed the title
Improve S1244: Add message to use "IsNan" instead of "== double.NaN"
Improve S1244: Add message to use "IsNaN" instead of "== double.NaN"
Dec 23, 2022
with exact values used in the messages for NaN, PositiveInfinity and NegativeInfinity, instead of the text with special values: any special value (namely constants defined in well-known floating-point types before .NET 7, and static abstract properties IFloatingPointIeee754<TSelf> since .NET 7) is also an exact value (such as 1.0, 2.3f, ...).
INumberBase.IsInfinity and INumberBase.IsFinite are methods checking multiple floating point values (IsInfinity checks for both PositiveInfinity and NegativeInfinity, IsFinite checks for zero and for all normal and subnormal values). As such they don't fall into the category of == Something, and are considered out of scope for this task.
Conversely, == type.IsNaN(), == type.IsPositiveInfinity() and == type.IsNegativeInfinity() all have corresponding constant or properties, and are considered in scope.
antonioaversa
changed the title
Improve S1244: Add message to use "IsNaN" instead of "== double.NaN"
Improve S1244: Add message to use "IsX" instead of "== double.X"
Jan 25, 2023
Description
S1244 (Floating point numbers should not be tested for equality) complains about a comparison like this
In this case, the message should read:
Do not check floating point equality with exact values, use double.IsNaN()
instead.The following methods should be supported:
INumberBase.IsFinite(TSelf) Method (System.Numerics) | Microsoft LearnINumberBase.IsInfinity(TSelf) Method (System.Numerics) | Microsoft LearnFor backward compatibility below .Net 7 double and float should be supported directly.
The text was updated successfully, but these errors were encountered: