Technical Considerations

NaNs

When a numeric operation cannot produce a meaningful result, the operation delivers a special bit pattern called a NaN (Not-a- Number). For example, zero divided by zero, +° added to -°, and Ã-1 yield NaNs. A NaN can occur in any of the numeric data formats (single, double, and double-double), but generally, system-specific integer types (non-numeric types exclusively for integer values) have no representation for NaNs.

A NaN may have an associated code that indicates its origin.

NaN Meaning

1 Invalid square root, such as Ã-1

2Invalid addition, such as (+°) + (-°)

4 Invalid division, such as 0Ö0

8 Invalid multiplication, such as 0x°

9 Invalid remainder or modulo, such as x rem 0 17 Attempt to convert invalid ASCII string

21 Attempt to create a NaN with a zero code

33 Invalid argument to trigonometric function (such as cos, sin, tan)

34 Invalid argument to inverse trigonometric function (such as acos, asin, atan)

36 Invalid argument to logarithmic function (such as log,

log10)

37Invalid argument to exponential function (such as exp, expm1)

38Invalid argument to financial function (compound or annuity)

40Invalid argument to inverse hyperbolic function (such as acosh, asinh)

42 Invalid argument to gamma function (gamma or lgamma)

Zeroes

Each floating-point format has two representations for zero: +0 and -0. Although the two zeros compare as equal (+0)=(-0), their behaviours in IEEE arithmetic are slightly different.

Ordinarily, the sign of zero does not matter except (possibly) for a function discontinuous at zero. Though the two forms are numerically equal, a program can distinguish +0 from -0 by operations such as division by zero or by performing the numeric copysign function.

The sign of zero obeys the usual sign laws for multiplication and division. For example, (+0)x(-1) = -0 and 1/(-0)= -°. Because

Technical Considerations

39

iMalc Manual

Page 45
Image 45
Apple 1.1.2 manual NaNs, Zeroes