What is the difference between #QNAN and #IND in Lua

If you run this through the Lua interpreter

print(0/0) print(-(0/0)) 

He outputs

 -1.#IND 1.#QNAN 

As far as I understand, both of them are Quiet Not-A-Numbers, but why #QNAN is equal -#IND (When I say "equal", I mean that they print the same thing, since I know that NaN != NaN )

Is there any benefit to knowing if NaN is #IND or #QNAN , and if so, what is the advantage.

+6
source share
1 answer

x86 indicates a special type of QNaN, the so-called undefined QNaN undefined (section 4.8.3.7 in IA32 Manual ):

For encodings of the floating point data type (single-precision, double precision, and double extended precision), one unique encoding (QNaN) is reserved to represent the undefined floating point QNaN special value. X87 FPUs and SSE / SSE2 / SSE3 / SSE4.1 / AVX Extensions return these undefined values ​​as responses to some masked floating point exceptions. Table 4-3 shows the encoding used for the QNaN undefined floating point.

This is what prints as -1.#IND according to your C library implementation.

In your case, operation 0/0 triggers a masked Invalid Operation Exception on the FPU, which is signaled by an undefined return value. In the case of -(0/0) you supply this undefined value as input to the negation operation, which returns QNaN.

The reason that different floating point operations give different error values ​​makes debugging easier. An experienced developer can more easily track an error if she knows exactly what NaN value is returned. For non-debugging purposes, since undefined is just a special kind of QNaN, you can often ignore the difference at all.

+7
source

Source: https://habr.com/ru/post/959155/


All Articles