CodeQL documentation

Wrong NaN comparison

ID: java/comparison-with-nan
Kind: problem
Security severity: 
Severity: error
Precision: very-high
Tags:
   - quality
   - reliability
   - correctness
Query suites:
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

The special floating-point number NaN is defined to be different from all other floating-point numbers, including itself, when compared using the equality operators, == and !=.

Recommendation

To check whether a variable x is NaN use the method isNaN that is defined on both java.lang.Float and java.lang.Double.

Example

The expression x == Double.NaN is always false. This expression should be replaced by Double.isNaN(x), which accurately identifies whether x is equal to Double.NaN.

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy