Arithmetic with NaNs

NaNs, though sometimes troublesome, are essential to the closure of the arithmetic. A NaN is the only reasonable response when the result of an operation is undefined; the alternatives are to stop the computation or to return an undeserved numerical result.

These lines appear in the SampleArcTanh listing at the beginning of this section.

      tmp = 0.5 * Log1Plus(2.0 * tmp / (1.0 - tmp));
      return CopySign(tmp, x);
Suppose tmp is 3, well outside the domain of arctanh. Then the argument to Log1Plus is , resulting in the attempt to compute , an invalid operation. The result is a NaN (with the invalid flag raised as a side effect), which passes through the multiplication by 0.5 unchanged and is assigned to tmp. Operations on NaNs are defined as straightforwardly as possible. CopySign places the sign of x onto the NaN in tmp, and the return coerces it to a double NaN.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker