Added to Favorites

Related Searches

Definitions

Nearby Words

In computing, NaN (Not a Number) is a value or symbol that is usually produced as the result of an operation on invalid input operands, especially in floating-point calculations. For example, most floating-point units are unable to explicitly calculate the square root of negative numbers, and will instead indicate that the operation was invalid and return a NaN result.

IEEE 754 NaNs are represented with the exponential field filled with ones and some non-zero number in the significand. A bit-wise example of a IEEE floating-point standard single precision NaN: x11111111axxxxxxxxxxxxxxxxxxxxxx. x = undefined. If a = 1, it is a quiet NaN, otherwise it is a signalling NaN.

A NaN does not compare equal to any floating-point number or NaN, even if the latter has an identical representation. One can therefore test whether a variable has a NaN value by comparing it to itself (i.e. if $x\; neq\; x$ then x is NaN).

In the IEEE floating-point standard, arithmetic operations involving NaN always produce NaN, allowing the value to propagate through a calculation so that errors can be detected early.

In the proposed IEEE 754r revision of that standard the same rule applies, except that a few anomalous functions (such as the maxnum function, which returns the maximum of two operands which are expected to be numbers) favour numbers—if just one of the operands is a NaN then the value of the other operand is returned.

A different approach has been implemented in the NaN 'toolbox' for GNU Octave and MATLAB. In that toolbox, NaNs are assumed to represent missing values and so the statistical functions ignore NaNs in the data instead of propagating them. Every computation in the NaN toolbox is based on the data values only, which can be useful if it is known that NaNs cannot be produced by errors.

The following practices may cause NaNs:

- All mathematical operations with a NaN as at least one operand
- The divisions 0/0, ∞/∞, ∞/-∞, -∞/∞, and -∞/-∞
- The multiplications 0×∞ and 0×-∞
- The additions ∞ + (-∞), (-∞) + ∞ and equivalent subtractions.
- Applying a function to arguments outside its domain, including taking the square root of a negative number, taking the logarithm of zero or a negative number, or taking the inverse sine or cosine of a number which is less than -1 or greater than +1.

However, it is important to realize that these NaNs are not necessarily generated by the processor. In the case of quiet NaNs the first item is always valid for each processor; the others may not necessarily be. For example, on the Intel Architecture processors, the FPU never creates a NaN except in the first case, unless the corresponding floating point exception mask bits have been set. The other items would cause exceptions, not NaNs. However, the software exception handler may examine the operands and decide to return a NaN (e.g. in the case of 0/0).

- Filling uninitialized memory with signalling NaNs would produce an invalid exception if the data is used before it is initialized
- Using an sNaN as a placeholder for a more complicated object such as:
- a representation of a number which has underflowed
- a representation of a number which has overflowed
- number in a higher precision format
- a complex number

When encountered a trap handler could decode the sNaN and return an index to the computed result. In practice this approach is faced with many complications. The treatment of the sign bit of NaNs for some simple operations (such as absolute value) is different than for arithmetic operations. Traps are not required by the standard. There are other approaches to this sort of problem which would be more portable.

There were questions about if signalling NaNs should continue to be required in the revised standard. In the end it appears they will be left in.

If we define pow(x,y) = x ** y

What is pow(1, NaN)?

The first view is that the output should be NaN since one of the inputs is. The second view is that since pow(1, y) = 1 for any real number y, or even if y is infinity or -infinity, then it is appropriate to return 1 for the case of pow(1, NaN). This is the approach in many math libraries.

A similar concern is for the test

(x <= infinity)

which is true for all extended real values of x. But in IEEE 754 (NaN <= infinity) is false.

Perl's BigInt package uses "NaN" for the result of strings which don't represent valid integers.

` >perl -mMath::BigInt -e "print Math::BigInt->new('foo')" `

` NaN `

nan

NaN

NaN%

NAN

NaNQ

NaNS

qNaN

sNaN

1.#SNAN

1.#QNAN

Since, in practice, encoded NaNs have both a sign and optional 'diagnostic information' (sometimes called a payload), these will often be found in string representations of NaNs, too, for example:

-NaN

NaN12345

-sNaN12300

(other variants exist)

The string representation "-1.#IND" is also encountered, which is not a NaN, but an indeterminate form.

On processors from Intel and AMD the first fraction bit of a binary significand is set to one for a qNaN and is zero for an sNaN. Other vendors use different schemes.

For the proposed IEEE 754r decimal encodings, Infinities and NaNs are distinguished at a 'higher level', and so there is no confusion between NaNs and Infinities. Therefore, in this case, a 1 is used (in the equivalent position) to indicate sNaN, because turning this to 0 still indicates a (quiet) NaN. Hence, an initialization of all-ones sets any storage for these encodings to signaling-NaN, which is an appropriate setting for 'uninitialized' numeric data.

- http://foldoc.org/?Not-a-Number

Wikipedia, the free encyclopedia © 2001-2006 Wikipedia contributors (Disclaimer)

This article is licensed under the GNU Free Documentation License.

Last updated on Tuesday August 26, 2008 at 10:46:52 PDT (GMT -0700)

View this article at Wikipedia.org - Edit this article at Wikipedia.org - Donate to the Wikimedia Foundation

This article is licensed under the GNU Free Documentation License.

Last updated on Tuesday August 26, 2008 at 10:46:52 PDT (GMT -0700)

View this article at Wikipedia.org - Edit this article at Wikipedia.org - Donate to the Wikimedia Foundation

Copyright © 2015 Dictionary.com, LLC. All rights reserved.