Skip to content

Files

Latest commit

 

History

History
23 lines (14 loc) · 689 Bytes

File metadata and controls

23 lines (14 loc) · 689 Bytes

Pattern: Malformed test for NaN

Issue: -

Description

System.Double.NaN, which represents a value that's not a number, results when an arithmetic operation is undefined. Any expression that tests for equality between a value and System.Double.NaN always returns false. Any expression that tests for inequality (!= in C#) between a value and System.Double.NaN always returns true.

Example of incorrect code:

Console.WriteLine(0 / zero == double.NaN);

Example of correct code:

Console.WriteLine(double.IsNaN(0 / zero));

Further Reading