Flylib.com

Books Software

 
 
 

4.5 Special Floating-Point Values


4.5 Special Floating-Point Values

The IEEE floating-point format provides a special encoding for several special values. In this section we'll look these special values, their purpose and meaning, and their representation in the floating-point format.

Under normal circumstances, the exponent bits of a floating-point number do not contain all zeros or all ones. An exponent containing all one or zero bits indicates a special value.

If the exponent contains all ones and the mantissa is nonzero (discounting the implied bit), then the HO bit of the mantissa (again discounting the implied bit) determines whether the value represents a quiet not-a-number (QNaN) or a signaling not-a-number (SNaN) (see Table 4-1). These not-a-number (NaN) results tell the system that some serious miscalculation has taken place and that the result of the calculation is completely undefined. QNaNs represent indeterminate results, while SNaNs specify that an invalid operation has taken place. Any calculation involving a NaN produces an NaN result, regardless of the values of any other operand(s). Note that the sign bit is irrelevant for NaNs. The binary representations of NaNs are shown in Table 4-1.

Table 4-1: Binary Representations for NaN

NaN

FP Format

Value

SNaN

32 bits

%s_11111111_0xxxx...xx

(The value of s value is irrelevant - at least one of the x bits must be nonzero.)

SNaN

64 bits

%s_1111111111_0xxxxx...x

(The value of s is irrelevant - at least one of the x bits must be nonzero.)

SNaN

80 bits

%s_1111111111_0xxxxx...x

(The value of s is irrelevant - at least one of the x bits must be nonzero.)

QNaN

32 bits

%s_11111111_1xxxx...xx

(The value of s is irrelevant.)

QNaN

64 bits

%s_1111111111_1xxxxx...x

(The value of s is irrelevant.)

QNaN

80 bits

%s_1111111111_1xxxxx...x

(The value of s is irrelevant.)

Two other special values are represented when the exponent contains all one bits, and the mantissa contains all zeros. In such a case, the sign bit determines whether the result is the representation for + infinity or ˆ’ infinity . Whenever a calculation involves infinity as one of the operands, the arithmetic operation will produce one of the ( well-defined ) values found in Table 4-2.

Table 4-2: Operations Involving Infinity

Operation

Result

n / ±infinity

±infinity — ±infinity

±infinity

±nonzero / 0

±infinity

infinity + infinity

infinity

n + infinity

infinity

n ˆ’ infinity

ˆ’ infinity

±0 / ±0

NaN

infinity ˆ’ infinity

NaN

±infinity / ±infinity

NaN

±infinity — 0

NaN

{% if main.adsdop %}{% include 'adsenceinline.tpl' %}{% endif %}

Finally, if the exponent bits are all zero, the sign bit indicates which of the two special values, ˆ’ 0 or +0, the floating-point number represents. Because the floating-point format uses a one's complement notation, there are two separate representations for zero. Note that with respect to comparisons, arithmetic, and other operations, +0 is equal to ˆ’ 0.



4.6 Floating-Point Exceptions

The IEEE floating-point standard defines certain degenerate conditions under which the floating-point processor (or software-implemented floating-point code) should possibly notify the application software. These exceptional conditions include the following:

  • Invalid operation

  • Division by zero

  • Denormalized operand

  • Numeric overflow

  • Numeric underflow

  • Inexact result

Of these, inexact result is the least serious, because most floating calculations will produce an inexact result. A denormalized operand also isn't too serious (though this exception indicates that your calculation may be less accurate as a result of less available precision). The other exceptions indicate a more serious problem, and you shouldn't ignore them.

How the computer system notifies your application of these exceptions depends on the CPU/FPU, operating system, and programming language, so we can't really go into how one might handle these exceptions. Generally, though, you can use the exception-handling facilities in your programming language to trap these conditions as they occur in your particular environment. Note that most computer systems require that you explicitly tell them to generate a notification for these exceptional conditions; otherwise , the system will not notify you when one of the exceptional conditions exist.