background image

Vol. 1 4-17

DATA TYPES

the element. Then, if an application program attempts to access an element that it has not initialized, it can use the 
NaN placed there by the compiler. If the invalid operation exception is unmasked, an interrupt will occur, and the 
exception handler will be invoked. The exception handler can determine which element has been accessed, since 
the operand address field of the exception pointer will point to the NaN, and the NaN will contain the index number 
of the array element.
Quiet NaNs are often used to speed up debugging. In its early testing phase, a program often contains multiple 
errors. An exception handler can be written to save diagnostic information in memory whenever it is invoked. After 
storing the diagnostic data, it can supply a quiet NaN as the result of the erroneous instruction, and that NaN can 
point to its associated diagnostic area in memory. The program will then continue, creating a different NaN for each 
error. When the program ends, the NaN results can be used to access the diagnostic data saved at the time the 
errors occurred. Many errors can thus be diagnosed and corrected in one test run.
In embedded applications that use computed results in further computations, an undetected QNaN can invalidate 
all subsequent results. Such applications should therefore periodically check for QNaNs and provide a recovery 
mechanism to be used if a QNaN result is detected. 

4.8.3.7  

QNaN Floating-Point Indefinite

For the floating-point data type encodings (single-precision, double-precision, and double-extended-precision), 
one unique encoding (a QNaN) is reserved for representing the special value QNaN floating-point indefinite. The 
x87 FPU and the SSE/SSE2/SSE3/SSE4.1/AVX extensions return these indefinite values as responses to some 
masked floating-point exceptions. Table 4-3 shows the encoding used for the QNaN floating-point indefinite.

4.8.3.8  

Half-Precision Floating-Point Operation

Half-precision floating-point values are not used by the processor directly for arithmetic operations. Two instruc-
tions, VCVTPH2PS, VCVTPS2PH, provide conversion only between half-precision and single-precision floating-point 
values.
The SIMD floating-point exception behavior of VCVTPH2PS and VCVTPS2PH are described in Section 14.4.1.

4.8.4 Rounding

When performing floating-point operations, the processor produces an infinitely precise floating-point result in the 
destination format (single-precision, double-precision, or double extended-precision floating-point) whenever 
possible. However, because only a subset of the numbers in the real number continuum can be represented in IEEE 
Standard 754 floating-point formats, it is often the case that an infinitely precise result cannot be encoded exactly 
in the format of the destination operand.
For example, the following value (a) has a 24-bit fraction. The least-significant bit of this fraction (the underlined 
bit) cannot be encoded exactly in the single-precision format (which has only a 23-bit fraction):
(a) 1.0001 0000 1000 0011 1001 0111E

2

 101

To round this result (a), the processor first selects two representable fractions and c that most closely bracket 
in value (c).
(b) 1.0001 0000 1000 0011 1001 011E

2

 101

(c) 1.0001 0000 1000 0011 1001 100E

2

 101

The processor then sets the result to or to c according to the selected rounding mode. Rounding introduces an 
error in a result that is less than one unit in the last place (the least significant bit position of the floating-point 
value) to which the result is rounded.
The IEEE Standard 754 defines four rounding modes (see Table 4-8): round to nearest, round up, round down, and 
round toward zero. The default rounding mode (for the Intel 64 and IA-32 architectures) is round to nearest. This 
mode provides the most accurate and statistically unbiased estimate of the true result and is suitable for most 
applications.