Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
NaN
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Comparison with NaN === Comparisons are specified by the [[IEEE 754]] standard to take into account possible NaN operands.<ref>{{Harvnb|IEEE 754|2019|loc=Β§5.11}}</ref> When comparing two real numbers, or [[Extended real number line|extended real numbers]] (as in the IEEE 754 floating-point formats), the first number may be either less than, equal to, or greater than the second number. This gives three possible relations. But when at least one operand of a comparison is NaN, this trichotomy does not apply, and a fourth relation is needed: ''unordered''. In particular, two NaN values compare as unordered, not as equal. As specified, the predicates associated with the <, β€, =, β₯, > mathematical symbols (or equivalent notation in programming languages) return false on an unordered relation. So, for instance, {{nobr|1=[[Negation|NOT]](''x'' < ''y'')}} is not logically equivalent to {{nobr|1=''x'' β₯ ''y''}}: on unordered, i.e. when ''x'' or ''y'' is NaN, the former returns true while the latter returns false. However, β is defined as the negation of =, thus it returns true on unordered. {| class="wikitable" style="text-align: center" |+ Comparison between NaN and any floating-point value ''x''<br />(including NaN and Β±β) ! Comparison | NaN β₯ ''x'' | NaN β€ ''x'' | NaN > ''x'' | NaN < ''x'' | NaN = ''x'' | NaN β ''x'' |- ! Result | False | False | False | False | False | True |} From these rules, comparing ''x'' with itself, {{nobr|1=''x'' β ''x''}} or {{nobr|1=''x'' = ''x''}}, can be used to test whether ''x'' is NaN or non-NaN. The comparison predicates are either signaling or non-signaling on quiet NaN operands; the signaling versions signal the invalid-operation [[IEEE 754#Exception handling|exception]] for such comparisons (i.e., by default, this just sets the corresponding status flag in addition to the behavior of the non-signaling versions). The equality and inequality predicates are non-signaling. The other standard comparison predicates associated with the above mathematical symbols are all signaling if they receive a NaN operand. The standard also provides non-signaling versions of these other predicates. The predicate <code>isNaN(''x'')</code> determines whether a value is a NaN and never signals an exception, even if ''x'' is a signaling NaN. The [[IEEE 754|IEEE floating-point]] standard requires that ''NaN β NaN'' hold. In contrast, the 2022 [[technical standard|private standard]] of [[posit (number format)|posit]] arithmetic has a similar concept, NaR (Not a Real), where ''NaR = NaR'' holds.<ref>[https://posithub.org/docs/posit_standard-2.pdf Standard for Posit Arithmetic (2022)]</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)