-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathWrongNanComparison.qhelp
More file actions
32 lines (27 loc) · 1003 Bytes
/
WrongNanComparison.qhelp
File metadata and controls
32 lines (27 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>The special floating-point number <code>NaN</code> is defined to be different from all other
floating-point numbers, including itself, when compared using the equality operators,
<code>==</code> and <code>!=</code>.
</p>
</overview>
<recommendation>
<p>To check whether a variable <code>x</code> is <code>NaN</code> use the method <code>isNaN</code>
that is defined on both <code>java.lang.Float</code> and <code>java.lang.Double</code>.
</p>
</recommendation>
<example>
<p>The expression <code>x == Double.NaN</code> is always false. This expression should be replaced
by <code>Double.isNaN(x)</code>, which accurately identifies whether <code>x</code> is equal to <code>Double.NaN</code>.
</p>
</example>
<references>
<li>
Java Language Specification:
<a href="https://docs.oracle.com/javase/specs/jls/se11/html/jls-15.html#jls-15.21.1">Numerical Equality Operators == and !=</a>.
</li>
</references>
</qhelp>