Why some numbers are defined as not a number(NaN) in floating point arithmetic? (Although they can be represented by IEEE format and indeed are real numbers)
Not a Number (NaN)
1k Views Asked by Lavlesh Mishra At
2
There are 2 best solutions below
0
Paul Floyd
On
The special cases of Inf and NaN are not treated as numbers because they are Inf and NaN by definition. That definition is in section 6.2.1 of IEEE 754-2008 (not a free standard).
The generation and propagation of NaNs is handled in hardware (at least on Intel hardware, see "Intel® 64 and IA-32 Architectures Software Developer’s Manual" as an example, specifically E4.2.2 which covers it in detail).
Related Questions in FLOATING-POINT
- Significant digits with IEEE 754 float
- Randomizing values accounting for floating point resolution
- Why is this floating point addition result not correct?
- Numerical issue with np.exp()
- Converting float to uint64 and uint32 behaves strangely
- Addition of floating point, Why the First code work
- how divided integer is converted to floating point number with decimal
- Trouble outputting Float value using Jackson library for Java
- Simple and clean java float to string conversion
- Does OCaml have C-like round() and trunc() functions?
- Splitting a floating point number into a sum of two other numbers, without rounding errors
- How to tell if up to floating point round-off, 4 2-d points might lie on a common circle?
- Is it always safe to negate a floating point number
- Why is the value of 1**Inf equal to 1, not NaN?
- Check if given number is Even, Odd or Neither in PHP?
Related Questions in NUMBER-FORMATTING
- google vizualization wrong number format
- PHP Round With Decimal & Comma $1,000
- NumberFormat parse not strict enough
- Most concise way to convert string to integer in Scala?
- Different output when using cout + printf vs printf only
- JQuery Knob - number format
- How do I format a number in Jquery without a plugin?
- How to find string value is in exponential format in C#?
- Numberformat that allows me to enter formulas but stores values as text?
- Number format in CSV file
- RoundingMode.UNNECESSARY throws exception
- (VBA Excel) Extract Text and related Letter from String and output result
- Javascript get decimal and thousands separator from NumberFormat
- Cannot format numbers after migration to struts 2
- Separate number with commas after 3 digits white managing decimal places on a string iOS
Related Questions in ARITHMETICEXCEPTION
- Possible solutions to BigDecimal underflow error
- Cloning Git repository throwing ArithmeticException
- Exception in thread "main" java.lang.ArithmeticException: / by zero
- How to solve ArithmeticException Error : / by zero
- Division by zero doesn't always throw java.lang.ArithmeticException
- A fatal error has been detected by the Java Runtime Environment while using arithmetic exception in Mac
- java.lang.RuntimeException - Caused by: java.lang.ArithmeticException
- Not a Number (NaN)
- Certain BigDecimal numbers in Java when divided causes the ArithmeticException to be thrown
- Why does division by zero with floating point (or double precision) numbers not throw java.lang.ArithmeticException: / by zero in Java
- Why try-catch is not giving the desired output?
- ArithmeticException in C# code after calling C function from dll
- Why does (int)(2/0.9) = 2?
- Why does ambiguity not raised for ArithmeticException parameter method
- ArithmeticException not thrown for overflow within 2^32
Related Questions in ARITHMETIC-OVERFLOW
- Arithmetic Overflow Error When running Update-Database EFCore
- Not a Number (NaN)
- Converting a bigint timestamp/TIMESTAMP_MICROS to datetime2 in Azure SQL Server doesn't work - error Arithmetic overflow converting expression to int
- stored procedure failing with "Arithmetic overflow error converting varchar to data type numeric." error even though I cast all fields explicitly
- Arithmetic overflow converting to int when inserting 2,147,483,648 or greater into decimal(18,6) column in SQL Server database table
- Arithmetic overflow expected but does not occur
- How to correct Arithmetic overflow error converting nvarchar to numeric for sql datatype numeric(9, 4)?
- How to prevent arithmetic overflow from corrupting the internal state of a class?
- Can't add two 32 bit numbers on MIPS
- Arithmetic overflow error converting numeric to data type numeric
- Arithmetic overflow error for type int, value = 4957500001.400178
- How to get rid of the arithmetic overflow
- Arithmetic overflow using all 32-bit ints in C++?
- Arithmetic overflow depending on group by columns
- Arithmetic overflow error sql
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The author of the question also posted this comment:
The reasoning behind this comment appears to be: A binary floating-point format has a sign bit s, some exponent bits e, and some significand bits f. For most values of e, the value represented is (−1)s•1.f•2e-bias (where “1.f” is the binary numeral formed by concatenating “1.“ and the bits f and bias is the encoding bias for the exponent). With this scheme, an exponent value of all ones would be a number, so how is it a NaN?
The answer is that the IEEE-754 standard specifies what the bits of a floating-point encoding represent, and it states that:
The fact there is a pattern of values represented for the values of e between (but not including) all zeros and all ones does not mean the pattern must extended to when e is all zeros or all ones. Nothing about logic or physics compels us to design hardware that extends the pattern to all values of e. The rules were made as described as above, and implementations of IEEE-754 floating-point follow those rules.
Additionally, the values described above form a set that IEEE-754 calls floating-point data. That set includes −∞ and +∞, the various non-zero real numbers arising from values of s, e, and f, two “zeros” distinguished by sign: −0 and +0, and NaN. Much of the IEEE-754 specification of arithmetic operations then uses those values. For example, addition is defined to produce a result as if the exact mathematical sum were calculated and then a rounding rule were applied to it. Each rounding rule specifies that, if the value goes out of certain bounds, the result is an infinity. Otherwise, the exact mathematical sum is rounded to the nearest representable value in a direction specified by the rounding rule (such as nearest in either direction, toward +∞, toward −∞, or toward zero).
So, when IEEE-754 is implemented, in either hardware or software, the implementation is designed to follow these rules. When the rules say that infinity is to be produced, the implementation produces the bit pattern that represents an infinity. When an input operand has the bit pattern for infinity, the implementation treats it as infinity, not as the real number it would represent if the exponent encoding had a meaning that extended the pattern of normal numbers.