Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
NaN
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
NaN
(section)
Add topic