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
- Imprecision in float integers in C
- printf floating-point output variations only with alpine docker on Windows
- Is it possible to represent -3/32 as a binary floating-point value using only 7 bits
- Pytorch sum problem (possibly floating point)
- Example of Code with and without strictfp Modifier
- Why does numpy's `2**np.array([64])` produces 0, whereas plain python's 2**64 gives the correct result?
- How does floating-point addition work in "np.finfo(np.float64).max + 1"?
- Problem caused by FP16 group quantization on vit-tiny
- How to format float to omit zeros at the end of the fraction
- TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe' again
- Why wont variables in the list print to 3 decimal places?
- How to print all the decimals of a float 128 to the console
- How to specify a float/decimal value for a column inside an insert in liquibase changelog?
- Why does gcc -O1 affects std::rint()?
- Sign of result of addition in floating point arithmetic
Related Questions in NUMBER-FORMATTING
- How to handle decimal input values in a globalized MVC app
- React Native TextInput Format Number Amount Comma Separated Number with Decimal Points with two state values
- Concatenate two digit year with number formatted with leading zeros
- Format value for string typed large number in OpenAPI Specification
- how to number value in convert in indian currency format. like (120000 to 1.2Lakh & 50000000 to 5Cr
- NumberFormat.parse("3.14") returning 314 when used with German Locale
- Gravity Forms Dropdown List Display
- Problem with OpenXML Library in C#: Numbers Not Recognized in Excel File Creation
- Conversion from MIFARE 14 byte UID to unknown 5 byte number
- How to display correct values for Min, Max, Sum, and Average of negative integers
- How to display numeric value 0.0 as 0.00 as the query result
- dart numberformat how to set round or floor with some other case
- locale attribute in convertNumber tag in XHTML not working in Tomcat
- What's the solution and the right way to convert digits in JavaScript?
- Number formatting based on cell value using vba function
Related Questions in ARITHMETICEXCEPTION
- Why doesn't Java treat explicit division by zero as a compile-time exception?
- How to solve ArithmeticException Error : / by zero
- Division by zero doesn't always throw java.lang.ArithmeticException
- ArithmeticException not being caught
- Why overriding a parent class method and adding throws statement in a child class generating an compile time error in java
- Arithmetic exception in C
- Why try-catch is not giving the desired output?
- java.lang.RuntimeException - Caused by: java.lang.ArithmeticException
- A fatal error has been detected by the Java Runtime Environment while using arithmetic exception in Mac
- Exception in thread awt-eventqueue-2 java.lang.ArithmeticException / by Zero
- Fortran 90 GDB signal SIGFPE, Arithmetic exception
- Why am I getting java.lang.ArithmeticException: divide by zero
- Cannot work around ArithmeticException? / by zero?
- Why does the program not terminate despite exception in java?
- Why am I getting a System.ArithmeticException with C#'s Nuget BigInteger 1.0.7?
Related Questions in ARITHMETIC-OVERFLOW
- Converting a bigint timestamp/TIMESTAMP_MICROS to datetime2 in Azure SQL Server doesn't work - error Arithmetic overflow converting expression to int
- how to resolve Arithmetic overflow error in Databricks SQL Editor
- Arithmetic overflow depending on group by columns
- How to prevent arithmetic overflow from corrupting the internal state of a class?
- Arithmetic overflow using all 32-bit ints in C++?
- Arithmetic Overflow Error When running Update-Database EFCore
- Arithmetic overflow expected but does not occur
- Arithmetic overflow converting to int when inserting 2,147,483,648 or greater into decimal(18,6) column in SQL Server database table
- stored procedure failing with "Arithmetic overflow error converting varchar to data type numeric." error even though I cast all fields explicitly
- prevent arithmetic overflow
- How to get rid of the arithmetic overflow
- How to correct Arithmetic overflow error converting nvarchar to numeric for sql datatype numeric(9, 4)?
- MSVC compiler bug when adding 0 to a pointer with /arch:AVX2; related to Warning C26451
- c#: adding two big integers gives wrong result
- Can't add two 32 bit numbers on MIPS
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 # Hahtags
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.