GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Wrong NaN comparison — CodeQL query help 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-code-quality.qls
   - 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¶

  • Java Language Specification: Numerical Equality Operators == and !=.

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.